HTTP methods define how a client communicates with a server. They describe the type of action to perform on a resource such as fetching data, creating records, updating content, or deleting data. These methods are heavily used in REST APIs and tools like Postman.
Each HTTP request consists of a method, URL, headers, and optionally a body. The server responds with a status code such as 200 (OK), 201 (Created), 404 (Not Found), or 500 (Server Error).
// GET request example using fetch API
fetch("https://api.example.com/users")
.then(response => response.json())
.then(data => console.log(data));
// POST request to send new data to server
fetch("https://api.example.com/users", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "Meghraj", role: "Developer" })
});
// PUT request replaces the entire resource
fetch("https://api.example.com/users/1", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "Updated Name", role: "Admin" })
});
// PATCH request updates specific fields
fetch("https://api.example.com/users/1", {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ role: "Manager" })
});
// DELETE request removes a resource
fetch("https://api.example.com/users/1", {
method: "DELETE"
});
Click the buttons below to simulate a live API request and see the response.