axios.post('https://jsonplaceholder.typicode.com/posts', {
title: 'New Post',
body: 'This is the content of the new post.',
userId: 1
})
.then(response => {
console.log('Post created:', response.data);
})
.catch(error => {
console.error('Error creating post:', error);
});
- We use
axios.post()
to send a POST request to the API endpoint. - The second argument to
axios.post()
is the data object that will be sent with the request.