RESTful web services typically use the following HTTP methods (also known as HTTP verbs) to perform CRUD (Create, Read, Update, Delete) operations on resources:
- GET: The GET method is used to retrieve a representation of a resource or a collection of resources from the server. It is idempotent, meaning that multiple identical requests have the same effect as a single request. GET requests should not have any side effects on the server.
- POST: The POST method is used to create a new resource on the server. It typically includes a request payload containing the data for the new resource. POST requests are not idempotent, meaning that multiple identical requests may result in different outcomes.
- PUT: The PUT method is used to update an existing resource on the server or create a new resource if it does not exist. It typically includes a request payload containing the updated data for the resource. PUT requests are idempotent, meaning that multiple identical requests have the same effect as a single request.
- DELETE: The DELETE method is used to delete a resource from the server. It does not include a request payload, as the resource to be deleted is typically identified by its URI. DELETE requests are idempotent, meaning that multiple identical requests have the same effect as a single request.
- PATCH: The PATCH method is used to partially update an existing resource on the server. It allows clients to send a set of changes to be applied to the resource, rather than replacing the entire resource with a new representation. PATCH requests are not always idempotent, as the effect of multiple identical requests may depend on the state of the resource.
In addition to these standard HTTP methods, RESTful web services may also define custom methods or actions using HTTP extensions such as:
- HEAD: The HEAD method is similar to the GET method, but it only retrieves the headers of the response without the response body. It is often used to check the status or metadata of a resource without transferring the entire representation.
- OPTIONS: The OPTIONS method is used to retrieve the communication options available for a given resource or server. It allows clients to determine which HTTP methods are supported by the server for a particular resource.
- TRACE: The TRACE method is used to echo the received request back to the client, allowing clients to see what changes or additions have been made by intermediate servers or proxies.
These HTTP methods provide a standardized way for clients to interact with RESTful web services and perform various operations on resources. By adhering to the semantics and conventions of these HTTP methods, RESTful APIs promote simplicity, interoperability, and scalability in web service development.