Skip to content

Instantly share code, notes, and snippets.

@souhe
Last active August 9, 2016 12:15
Show Gist options
  • Save souhe/31f42469cd0dcedc56799ed551bf2dc3 to your computer and use it in GitHub Desktop.
Save souhe/31f42469cd0dcedc56799ed551bf2dc3 to your computer and use it in GitHub Desktop.
callstackFetch basic specification
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