In RESTful web services, the HTTP protocol is used to exchange data between the client and the server. The following are the commonly used HTTP methods (also called HTTP verbs) in RESTful web services:
GET: The GET method is used to retrieve a resource or a collection of resources from the server. It is a safe and idempotent operation, meaning it does not modify the resource on the server and can be called multiple times without changing the resource.
Example:
GET http://example.com/customers/123
POST: The POST method is used to create a new resource on the server or to submit data to a resource for processing. It is not idempotent, meaning calling it multiple times can create multiple resources with the same data.
Example:
POST http://example.com/customers
{
"name": "John Smith",
"email": "john@example.com"
}
PUT: The PUT method is used to update a resource on the server. It is idempotent, meaning calling it multiple times with the same data will not change the resource multiple times.
Example:
PUT http://example.com/customers/123
{
"name": "John Smith",
"email": "john.smith@example.com"
}
DELETE: The DELETE method is used to delete a resource on the server. It is idempotent, meaning calling it multiple times with the same resource will not have any additional effect.
Example:
DELETE http://example.com/customers/123
PATCH: The PATCH method is used to partially update a resource on the server. It is not idempotent, meaning calling it multiple times can result in different changes to the resource.
Example:
PATCH http://example.com/customers/123
{
"email": "john.smith@example.com"
}
HEAD: The HEAD method is used to retrieve the headers for a resource without retrieving the resource itself. It is a safe and idempotent operation.
Example:
HEAD http://example.com/customers/123
OPTIONS: The OPTIONS method is used to retrieve the supported methods for a resource. It is a safe and idempotent operation.
Example:
OPTIONS http://example.com/customers/123
In summary, these HTTP methods are the most commonly used in RESTful web services, and they provide a simple and powerful way to manipulate resources on the server.