Skip to content

Instantly share code, notes, and snippets.

@navio
Created January 20, 2018 03:52
Show Gist options
  • Save navio/2d6f98a67d93c5683524ad45c9bdedbd to your computer and use it in GitHub Desktop.
Save navio/2d6f98a67d93c5683524ad45c9bdedbd to your computer and use it in GitHub Desktop.
Fetch Async Method
export default async (url,method,json) => {
if(typeof method !== 'string' ) return fetch(url,fetch);
let response = await fetch(url,{
method,
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify(json)
}).then(x=>x.json());
return await response;
};
///jsonfetch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment