Thursday, 11 October 2018

appolo-link-rest set header

I am trying to use apollo-link-rest with a api-key set in the header. If I try to use the exact same api endpoint and set the api-key as header in Postman app, it works perfectly fine. But not for apollo-link-rest:

import { AppContainer } from 'react-hot-loader';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './react-components/App';
import PropTypes from 'prop-types';
import { RestLink } from "apollo-link-rest";
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloProvider } from 'react-apollo';
import 'normalize.css/normalize.css';
import './index.css';

const restLink = new RestLink({
    uri: 'https://a-site.net/api',
    headers: {
        'x-someapikey': '012737465334232522z2z22163r43'
    },
});

const client = new ApolloClient({
  link: restLink,
  cache: new InMemoryCache(),
});

What I am doing wrong?

Thats the Request Header printed in Chrome Devtools:

Request Header printed in Chrome Devtools

I get a 401 Error in Browser (Apollo)... But when I use the same endpoint with the same header in Postman app... it works!



from appolo-link-rest set header

No comments:

Post a Comment