post req in fetch code example
Example 1: fetch post json
(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);
})();
Example 2: how to post data using fethch
fetch('url here', {
method: 'POST',
headers: {'Content-Type':'application/x-www-form-urlencoded'},
body: 'foo=bar&blah=1'
});