Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind Authorization Header With a Specific Endpoint on Every Request #174

Closed
zicodeng opened this issue Nov 15, 2018 · 3 comments
Closed

Comments

@zicodeng
Copy link

Hi, I have two endpoints, but only one of them requires Authorization header on every request. How can I achieve this?

For example:

const restLink = new RestLink({
  endpoints: {
    v1: '...',
    v2: '...',
  },
  uri: '...',
  headers: {
    Authorization: '...'
  }
})

The above code will add Authorization on both v1 and v2 endpoints, but I only want v1 to have Authorization header.

Thanks!

@fbartho
Copy link
Collaborator

fbartho commented Nov 15, 2018

You might be able to build a context-link that reads the @rest(…) data to figure out what headers to patch.

Alternatively, you can provide a customFetch implementation (wrap fetch & delete that header if hitting v2) -- I'm sure this would work today!

@zicodeng
Copy link
Author

@fbartho Thanks for your help. Tried both approaches and worked!

Link Context requires to check query name whereas customFetch gives me request URL and I can apply different headers based on that.

Which way do you guys recommend?

@fbartho
Copy link
Collaborator

fbartho commented Nov 15, 2018

Sounds like customFetch is easiest for you, I recommend that 😉.

If you think we need per-endpoints headers or other tooling, that could be a useful enhancement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants