isomorphic-unfetch decorator
npm install isomorphic-unfetch-api-serviceWhy
To be able to make server/client side requests with the same service, with common headers preset, and a standard output data shape.
Installation
```
npm install isomorphic-unfetch-api-service
Usage
`isomorphic-unfetch-api-service
const ApiService = require();
const apiServiceInstance = new ApiService()
apiServiceInstance.get('/api/thing')
.then(res => {
// res is a JSON object/array
})
.catch(error => {
// error is a message
})
;
`
If the url needs a token or you are calling the same host, you can set it by extending the ApiService extendPath method:
`
const ApiService = require(isomorphic-unfetch-api-service);
class PathwaysApiService extends ApiService {
extendPath = path => {
const delimiter = path.indexOf(?) === -1 ? ? : &;${process.env.API_URI}${path}${delimiter}token=${process.env.API_TOKEN}
return ;
}
}
module.exports = new PathwaysApiService()
;
``