HTTP methods are the actions that can be performed on resources identified by URLs. They are used to communicate with a server and manipulate data. Here are the most commonly used HTTP methods:
- GET: Retrieve data from a server.
- POST: Send data to a server to create or update a resource.
- PUT: Update a resource on the server.
- DELETE: Remove a resource from the server.
- PATCH: Apply partial modifications to a resource.
GET Method
The GET method is used to retrieve data from a server. It is safe and idempotent, meaning that it can be repeated without causing any harmful effects.
Example
GET /api/users
This request will return a list of users.
POST Method
The POST method is used to send data to a server to create or update a resource. It is not safe and is idempotent.
Example
POST /api/users
Content-Type: application/json
{
"name": "John Doe",
"email": "john.doe@example.com"
}
This request will create a new user with the name "John Doe" and email "john.doe@example.com".
PUT Method
The PUT method is used to update a resource on the server. It is idempotent, meaning that it can be repeated without causing any harmful effects.
Example
PUT /api/users/123
Content-Type: application/json
{
"name": "Jane Doe",
"email": "jane.doe@example.com"
}
This request will update the user with ID 123 to have the name "Jane Doe" and email "jane.doe@example.com".
DELETE Method
The DELETE method is used to remove a resource from the server. It is idempotent, meaning that it can be repeated without causing any harmful effects.
Example
DELETE /api/users/123
This request will remove the user with ID 123.
PATCH Method
The PATCH method is used to apply partial modifications to a resource. It is idempotent, meaning that it can be repeated without causing any harmful effects.
Example
PATCH /api/users/123
Content-Type: application/json
{
"name": "Jane Doe"
}
This request will update the user with ID 123 to have the name "Jane Doe".
For more information on HTTP methods, please refer to our HTTP Methods Documentation.