Skip to content

Instantly share code, notes, and snippets.

@whoisryosuke
Created November 29, 2021 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save whoisryosuke/a9e0aa879549f8d5e1ef9235c7e82565 to your computer and use it in GitHub Desktop.
Save whoisryosuke/a9e0aa879549f8d5e1ef9235c7e82565 to your computer and use it in GitHub Desktop.
JS - Fetch POST request as async function
(async () => {
const rawResponse = await fetch('https://httpbin.org/post', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({a: 1, b: 'Textual content'})
});
const content = await rawResponse.json();
console.log(content);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment