HTTP Methods: GET, POST, PUT, DELETE, and More
GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, HTTP methods, idempotent, safe methods, CRUD mapping
HTTP Methods: GET, POST, PUT, DELETE, and More
HTTP methods tell the server what action to perform on a resource. REST API design maps these methods to CRUD operations — Create, Read, Update, Delete — creating a uniform, predictable interface that any developer can understand without reading custom documentation.
GET: Reading Data
GET requests retrieve data from the server. They must never modify data. GET requests are both safe (no side effects) and idempotent (calling the same request multiple times produces the same result). Examples: GET /users returns a list of all users. GET /users/42 returns the specific user with ID 42. GET requests never have a request body — all parameters go in the URL.
POST: Creating Data
POST requests submit data to the server to create a new resource. They are neither safe nor idempotent — calling the same POST request twice creates two separate resources. The new resource's data is sent in the request body as JSON. A successful POST typically returns status 201 Created with the newly created resource in the response body and a Location header pointing to the new resource's URL.
PUT: Replacing Data
PUT requests replace an entire resource with the data in the request body. If the resource does not exist, some implementations will create it. PUT is idempotent — sending the same PUT request multiple times always results in the same state. Use PUT when the client sends the complete representation of the resource.
PATCH: Partially Updating Data
PATCH requests apply a partial update to a resource. Only the fields included in the request body are modified. PATCH is more efficient than PUT when updating a single field in a large object because you do not need to send the entire resource.
PATCH /api/users/42
{
"email": "newemail@example.com"
}DELETE: Removing Data
DELETE requests remove a resource. A successful deletion typically returns status 204 No Content with no response body, or 200 OK with a confirmation message. DELETE is idempotent: deleting the same resource twice should not cause an error.
HEAD and OPTIONS
HEAD works exactly like GET but returns only the headers, not the body. It is used to check if a resource exists or to get its metadata without downloading its content. OPTIONS returns the HTTP methods allowed on a specific endpoint. Browsers use OPTIONS for CORS preflight checks — automatically sent before cross-origin requests to verify permissions.
