Last active
August 9, 2016 12:15
-
-
Save souhe/31f42469cd0dcedc56799ed551bf2dc3 to your computer and use it in GitHub Desktop.
callstackFetch basic specification
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 { createFetch } from 'callstackFetch'; // or import callstackFetch from 'callstackFetch' | |
const customFetch = createFetch({ // or new callstackFetch({}) | |
onError: (parseError) => {}, | |
onSuccess: (parsedBody) => {}, | |
parseError: (error) => {}, | |
parseBody: (body) => {}, | |
parseResponseHeaders: (headers) => ({ page: headers.get('Link') }), | |
getUserToken: () => {}, | |
customHeaders: {}, | |
}); | |
// usage example | |
const customFetch = createFetch({ | |
onError: (parseError) => { store.dispatch(akcja(Object.keys(errors).map(k => errors[k])); }, | |
getUserToken: () => userTokenSelector(store.getState()), | |
}); | |
customFetch('url', { | |
method: 'post', | |
body: {}, | |
}).then((parsedBody, parsedHeaders, response) => { | |
}).catch((parsedErrors) => { | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment