1.0.2 • Published 7 years ago
fetchware-headers v1.0.2
fetchware-headers
Modifies all requests headers with specified values without changes to api
Installation
npm install --save fetchware-headers
Usage
Here is an example of usage with isomorphic-fetch.
const headers = require('fetchware-headers')
const isomorphicFetch = require('isomorphic-fetch') //or use your favorite fetch implementation
const fetch = headers({'Authorization': 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'})(isomorphicFetch)
Custom parameters
Decorator passes all arguments to decorated function. Useful for decorator interaction.
const headers = require('fetchware-headers')
const isomorphicFetch = require('isomorphic-fetch') //or use your favorite fetch implementation
const myFetchDecorator = fetch =>
(url, options, {log}) => {
if (log)
console.log(url)
return fetch(url, options)
}
let fetch = myFetchDecorator(isomorphicFetch)
fetch = headers({'Authorization': 'Basic YWxhZGRpbjpvcGVuc2VzYW1l'})(fetch)
fetch('http://github.com', {method: 'POST'}, {log: true})
Licence
MIT