POST JSON Data

Send a JSON payload to an API endpoint using POST.

Code

Utilities
const payload = {
  name: 'Alice',
  age: 30,
  active: true
};

const response = await fetch('https://httpbin.org/post', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify(payload)
});
await response.json();
Browser·fetch() may be limited by CORS

More JavaScript Snippets