HTTP (Hypertext Transfer Protocol) verbs, also known as HTTP methods, define the actions that can be performed on a resource over the internet. There are several HTTP verbs, but the most commonly used ones are:
- GET - retrieves a resource's representation identified by a URL.
- POST - submits an entity to a resource identified by a URL, causing a change in state or side effect on the server.
- PUT - updates a resource identified by a URL with a new representation.
- DELETE - deletes a resource identified by a URL.
- PATCH - updates a part of a resource identified by a URL with a new representation.
- HEAD - retrieves a resource's metadata identified by a URL, similar to GET but without the response body.
- OPTIONS - retrieves the HTTP methods that a resource supports.
Let's take an example of a blog post. You can use these HTTP verbs to interact with the blog post resource:
- GET - to retrieve the blog post details.
- POST - to create a new blog post.
- PUT - to update an existing blog post.
- DELETE - to delete an existing blog post.
- PATCH - to update a specific field of an existing blog post.
- HEAD - to retrieve the metadata of the blog post, such as last-modified date.
- OPTIONS - to retrieve the HTTP methods supported by the blog post resource.
In summary, HTTP verbs are used to interact with resources over the internet by defining the actions that can be performed on them. Each HTTP verb has a specific purpose and is used based on the desired action to be performed on the resource.