Skip to content
This repository has been archived by the owner on Feb 6, 2018. It is now read-only.

Allow using default fetch headers for all requests #72

Merged
merged 2 commits into from
Sep 9, 2016

Conversation

bahmutov
Copy link
Contributor

@bahmutov bahmutov commented Sep 7, 2016

In situation where the server requires some specific headers, this allows to set them once and then use on each request

const feathers = require('feathers')
const rest = require('feathers-rest/client')
const fetch = require('node-fetch')
const headers = {
   whatever: 'I need'
}
const restClient = rest('https://my.url').fetch(fetch, {headers})
const app = feathers().configure(restClient)

In situation where the server requires some specific headers, this allows to set them once and then use on each request
```js
const feathers = require('feathers')
const rest = require('feathers-rest/client')
const fetch = require('node-fetch')
const headers = {
   whatever: 'I need'
}
const restClient = rest('https://my.url').fetch(fetch, {headers})
const app = feathers().configure(restClient)
```
@bahmutov
Copy link
Contributor Author

bahmutov commented Sep 7, 2016

Currently only request module supports defaults http://docs.feathersjs.com/clients/rest.html#request via its own mechanism

@daffl
Copy link
Member

daffl commented Sep 7, 2016

That is a great change. Would you mind adding the same thing for jQuery (at https://github.com/feathersjs/feathers-rest/blob/master/src/client/jquery.js#L5) as well?

@bahmutov
Copy link
Contributor Author

bahmutov commented Sep 7, 2016

will do tomorrow, thanks for quick look!

Should be enough to allow common headers with each REST call via jQuery ajax
```js
const headers = {
   whatever: 'I need'
}
const restClient = rest('https://my.url').jquery(jQuery, {headers})
const app = feathers().configure(restClient)
```
Relevant to jQuery ajax http://api.jquery.com/jquery.ajax/#jQuery-ajax-settings "headers" property
@daffl daffl merged commit bf8550f into feathersjs-ecosystem:master Sep 9, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants