Skip to content

Instantly share code, notes, and snippets.

@bfunc
Last active November 22, 2018 20:23
Show Gist options
  • Save bfunc/ac6d7455e99137852525a6bde148abe9 to your computer and use it in GitHub Desktop.
Save bfunc/ac6d7455e99137852525a6bde148abe9 to your computer and use it in GitHub Desktop.
http request window.fetch() snippet with application/json headers
fetch('http://HOST/api',
{
method: 'post', // 'put'
headers: { 'Accept': 'application/json, text/plain', 'Content-Type': 'application/json' },
body: JSON.stringify( {"User_employee_id":"1","template_id":0,"data":[{"id":1509003681672,"contract":"EuroDollar@SEP18"}]} ),
// cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
// credentials: 'same-origin', // include, same-origin, *omit
// mode: 'cors', // no-cors, cors, *same-origin
// redirect: 'follow', // manual, *follow, error
// referrer: 'no-referrer', // *client, no-referrer
})
.then(response => response.json())
.then(console.log)
.catch(console.warn);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment