How to fetch post json in JavaScript

JSON
By Jad Joubran · 
Last updated Feb 13, 2024
fetch("https://codetogo.io/api/users.json", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    key1: "value1"
  })
})
  .then(response => response.json())
  .then(data => {
    console.log(data);
  })
  .catch(console.error);
[{
    id: 1,
    name: "Sam"
}, {
    id: 2,
    name: "Alex"
}]
Fetch API use cases on Learn JavaScript