A way to send requests using JavaScript.

Sending JSON Data

const data = {
  title: "Hello World",
  body: "My POST request",
  userId: 900
};
 
fetch("https://jsonplaceholder.typicode.com/posts", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify(data)
})
.then(response => response.json())
.then(result => console.log(result))
.catch(error => console.error('Error:', error));

Sending Form Data

const formdata = new FormData();
formdata.append("name" : "daniel");
 
fetch("https://localhost:3000/posts", {
  method: "POST",
  body: formdata
})
.then(response => response.json())
.then(result => console.log(result))
.catch(error => console.error('Error:', error));