What is HTTP Methods?
Key Features of HTTP Methods.
- Idempotence: Idempotence ensures that performing an operation multiple times has the same effect as performing it once.
- Safety: Safety ensures that performing an operation does not have any side effects on the server.
- Statelessness: HTTP is inherently stateless, meaning each request from a client to a server is independent, and the server does not retain any knowledge of the client's previous requests.
- Content Negotiation: Content negotiation involves the client and server agreeing on the most suitable representation of a resource based on factors such as media type, language, or encoding.
- Uniform Interface: The uniform interface constraint in RESTful design emphasizes a consistent and standardized way of interacting with resources.
- Caching: Caching involves storing copies of resources to improve performance and reduce the load on servers.
- Security: Security considerations involve protecting against potential threats, ensuring secure communication, and handling sensitive data appropriately.
List of HTTP Methods.
| HTTP Method | Function |
|---|---|
| GET | The HTTP GET method is used to retrieve data from a specified resource on the server. |
| POST | The HTTP POST method is used to submit data to a specified resource, often causing a change in state or side effects on the server. |
| PUT | The HTTP PUT method is used to update or replace a resource on the server with the provided data payload. |
| DELETE | The HTTP DELETE method is used to request the removal of a specified resource on the server. |
| HEAD | The HTTP HEAD method is used to retrieve the headers of response for a specified resource, without the body content, allowing a client to check for for the resource's existence, modification date, or other metadata without downloading the full content. |
| OPTIONS | The HTTP OPTIONS method is used to request information about the communication options available for a target resource. |
| PATCH | The HTTP PATCH method allows clients to send a set of changes to be applied to a resource on the server, enabling partial updates without replacing the entire resource. |
| TRACE | The HTTP TRACE method is used for diagnostic purposes, allowing a client to retrieve the entire request as it travels through intermediaries, useful for throubleshooting or debugging network issues. |
GET Method.
- Fetching a webpage.
- Retrieving an image or other static resources.
- Retrieving data from an API.
GET /example/resource HTTP/1.1
POST Method.
- Submitting a web form with user input.
- Uploading files to the server.
- Sending data for processing, such as creating a new resource.
POST /login HTTP/1.1
Host: www.example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 27
username=johndoe&password=secure123
PUT Method.
- Updating user profile information.
- Uploading a new version of a file to a server.
PUT /user/profile HTTP/1.1
Host: www.example.com
Content-Type: application/json
Content-Length: 43
{
"username": "johndoe",
"email": "john.doe@example.com"
}
DELETE Method.
- Deleting a user account.
- Removing a file or document from a server.
DELETE /user/account HTTP/1.1 Host: www.example.com
HEAD Method.
- Checking the last modification timestamp of a resource.
- Verifying resource existence without downloading the entire content.
HEAD /images/logo.png HTTP/1.1 Host: www.example.com
OPTIONS Method.
- Checking which HTTP methods are supported by a server for a specific resource.
- Discovering allowed headers or authentication methods.
OPTIONS /api/data HTTP/1.1 Host: www.example.com
PATCH Method.
- Updating specific fields in an existing resource.
- Making incremental changes to a document or object.
PATCH /user/profile HTTP/1.1
Host: www.example.com
Content-Type: application/json
Content-Length: 20
{
"email": "newemail@example.com"
}
TRACE Method.
- Debugging and testing the communication path.
- Tracing the transformation of a request through proxies.
TRACE /api/data HTTP/1.1 Host: www.example.com



