Created
September 12, 2016 19:21
-
-
Save mimol91/87c2685e7f3b5d91bd0245b2af86b6a1 to your computer and use it in GitHub Desktop.
rest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rest from 'rest' | |
import hateoas from 'rest/interceptor/hateoas' | |
import mime from 'rest/interceptor/mime' | |
import interceptor from 'rest/interceptor' | |
import defaultRequest from 'rest/interceptor/defaultRequest' | |
import errorCode from 'rest/interceptor/errorCode' | |
const tokenRemoval = interceptor({ | |
response: (response, config, meta) => { | |
if (response.status.code === 401) { | |
// remove token | |
console.log('401!') | |
} | |
return response | |
} | |
}) | |
let client = rest | |
.wrap(tokenRemoval) | |
.wrap(errorCode, {code: 300}) | |
.wrap(defaultRequest, { | |
path: 'https://api-sandbox.slimpay.net/', | |
headers: {'Authorization': 'Bearer 91de6392-0f58-42b1-8728-33978cfcc2baz'} | |
}) | |
.wrap(mime) | |
.wrap(hateoas) | |
client() | |
.follow('profile') | |
.then((response) => { | |
console.log('response: ', response) | |
}) | |
.catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment