Category: java
HTTP POST Method
Published on 24 Feb 2026
Explanation
POST method is used to send data to
the server to create a resource.
Code:
fetch('https://api.example.com/users',
{ method: 'POST'});
Explanation
Sending JSON data in POST request.
Code:
fetch('https://api.example.com/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json'
},
body: JSON.stringify({ name: 'John' })
});
Explanation
Handling POST response.
Code:
fetch(url, options) .then(res => res.json()) .then(data => console.log(data));
Explanation
POST is not idempotent
(multiple calls create multiple resources).
Code:
// Calling POST multiple times may create duplicate records
Explanation
Using async/await with POST.
Code:
const res = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'Alice' })
});