Created
January 12, 2018 22:44
-
-
Save jadehopepunk/6d99bc9a61ae9ac8652d91f40c4637fa to your computer and use it in GitHub Desktop.
Revisions
-
jadehopepunk created this gist
Jan 12, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ export function fetchWithHeaders(url: string, jwt: ?string = null, params: ParamType = {}) { const customHeaders = params.headers || {} const otherParams = omit(params, 'headers') const headers = { 'X-Requested-With': 'XMLHttpRequest', 'X-CSRF-Token': window.rippleCSRF, Accept: 'application/json, text/plain, */*', 'Content-Type': 'application/json', ...customHeaders } if (jwt) { headers.Authorization = `Bearer ${jwt}` } const fetchParams = { ...otherParams, headers, credentials: 'same-origin' } if (params.data) { fetchParams.body = JSON.stringify(params.data) } return fetch(url, fetchParams) }