Home

Published

- 1 min read

node-fetch post request example

img of node-fetch post request example

The solution for this is noted below

node-fetch post request example

Solution

   let todo = {
	userId: 123,
	title: 'loren impsum doloris',
	completed: false
}

fetch('https://jsonplaceholder.typicode.com/todos', {
	method: 'POST',
	body: JSON.stringify(todo),
	headers: { 'Content-Type': 'application/json' }
})
	.then((res) => res.json())
	.then((json) => console.log(json))

Try other methods by searching on the site. That is if this doesn’t work