Fetch: POST JSON data Fetch: POST JSON data javascript javascript

Fetch: POST JSON data


With ES2017 async/await support, this is how to POST a JSON payload:

(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);})();