async function createPost() {
try {
const response = await fetch(
"https://jsonplaceholder.typicode.com/posts",
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
title: "Learning APIs",
body: "This is my first POST request.",
userId: 1
})
}
);
const data = await response.json();
console.log(data);
} catch (error) {
console.log(error.message);
}
}
createPost();
async function createPost() {
try {
const response = await fetch(
"https://jsonplaceholder.typicode.com/posts",
{
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
title: "Learning APIs",
body: "This is my first POST request.",
userId: 1
})
}
);
} catch (error) {
console.log(error.message);
}
}
createPost();