HTTP Verbs Demystified
Most of us are familiar with the essential HTTP methods - GET, POST, PUT, and DELETE - commonly used in web APIs. However, there are a total of 9 HTTP methods that define how we interact with web resources. While these four are the most frequent players in our web development toolbox, understanding all nine is crucial for mastering web communication. Let's explore them together!
1. GET
GET is the most common HTTP verb, used for retrieving data from a server. It's like asking for information. We use it when we want to read data from a resource without altering it.
Example:-
GET/api/Employees/{id}
it will retrieve data by using parameter {id} , without effecting other data related to {id} .
2. POST
POST is used to submit data to be processed to a specified resource. Think of it as sending data to a server to create a new resource. It's commonly used in forms and for creating new records.
Example:-
POST/api/Employees/TECHNOLOGY
It'll send data to a server to create a new resource. Data is included in the body of the request.
3. PUT
PUT is used to update a resource or create it if it doesn't exist. It's like sending a full replacement for the resource. It's commonly used for updating existing records.
Example:-
PUT/api/Employees/123
It is very similar to POST , but used to update an existing resource by refering the id i.e. {123}
4. DELETE
DELETE is used to request the removal of a resource. It's like telling the server to discard something.
Example:-
DELETE/api/Employees/123
It will delete the record by refering the id.
5. PATCH
PATCH is similar to PUT, but it's used to apply partial modifications to a resource. It's more efficient when you only need to update specific fields.
Example:-
PATCH/api/Employees/123{
"name":"Arya"}
领英推荐
If we want to update a record's very specific fields , then this method will come into picture.
6. HEAD
HEAD is like GET, but it only requests the headers of a resource, without the actual data. It's useful for checking resource metadata.
Example:-
HEAD/api/Employees
It is similar to GET , but does not return any list of employees.
7. OPTIONS
OPTIONS is used to describe the communication options for the target resource. It helps the client understand what methods and headers are allowed for a resource.
Example:-
OPTIONS/api/ARYA.html/123
8. TRACE
TRACE is rarely used in practice. It's used for diagnostic purposes, allowing a client to see what changes have been made to a resource as it's passed between intermediaries.
Example:-
TRACE/api/main.html
9. CONNECT
CONNECT is used to establish a network connection to a resource, typically for use with a proxy server. That means it creates end to end connection between client and a server .
Example:-
CONNECT www.myblogs.com:80
HTTP/1.1
CONCLUSION
These HTTP verbs is fundamental for anyone working with web services, APIs, or web development in general. They dictate how you interact with web resources, and using them correctly is key to building robust and secure applications.
In future issues of our newsletter, we'll delve deeper into each of these verbs, providing real-world examples and best practices for their usage.
Thank you for being part of our community, and stay tuned for more insightful content!
Senior quality engineer
1 年Truly knowledge