HTTP Request Methods

Table of contents
HTTP methods define actions that can be performed on resources. POST, GET, PUT and DELETE defines the CRUD operation of the resource. HEAD, CONNECT, OPTION, TRACE and PATCH define other important actions defined in HTTP.
POST: The POST method creates a new resource. It leads to a change in the state of the resource often adding an entity to the resource.
Response code 201(Created) if the new resource is created on the server.
Response code 200(OK) POST action doesn't create resources
GET: The GET method requests a representation of the specified resource. The GET method should only retrieve the data.
- Response code 200(OK).
PUT: The put method replaces all current representations of the target resource with the request payload.
- Response code 200(OK)
Response code 204(No Content)
DELETE: The delete method deletes the specified resource.
- Response code 200(OK)
HEAD: The HEAD method asks for a response identical to the GET request, but without the response body. The HEAD method returns the headers that would return if the GET method is used instead. Use case, if a URL might produce a large download, a HEAD request could read its Content-Length header to check the filesize without actually downloading the file.
- Response code 200(OK)
CONNECT: The connect method establishes a tunnel to the server identified by the target. It is used to start two-way communications with the requested resource. The CONNECT method can be used to access websites that use SSL(HTTPS). The client asks an HTTP Proxy Server to tunnel the TCP connection to the desired destination. The proxy server then proceeds to make the connection on behalf of the client. Once the connection has been established by the server, the Proxy server continues to proxy the TCP stream to and from the client.
OPTION: The OPTIONS method describes the communication options for the target resource. The OPTIONS request method can be used to identify allowed request methods on the server. The response then contains an Allow header that holds the allowed methods. IN CORS(Cross-origin resource sharing), a preflight request is sent with the OPTIONS method so that the server can respond if it is acceptable to send the request.
TRACE: The TRACE method performs a message loop-back test along the path to the target resource, providing a useful debugging mechanism. The client sends the HTTP TRACE request to the server to validate the HTTP connection to the resource and determine if any change is made by intermediaries. The server responds with 200 OK and a copy of the original HTTP request in the message body, as well as a list of proxy servers that are passed through in the via HTTP header. It is useful for debugging routing errors. The Max-Forwards is an HTTP header to a specific number of nodes (usually proxies) that the request goes through.
- Response code 200(message)
PATCH: The patch method applies partial modification to a resource. A PATCH request is considered a set of instructions on how to modify a resource. It differs from PUT which is a complete representation of a resource.
HTTP Request features
Safe: A HTTP method is safe if it doesn't alter the state of the server. Ex: GET,TRACE, CONNECT, OPTION AND HEAD.
Idempotent: An HTTP method is idempotent if the intended effects on the server of making a single request is same as the effect of making serveral identifical requests. Ex: GET, PUT,DELETE,TRACE, OPTIONS AND HEAD.
Cacheable: A cacheable response is an HTTP response that can be caches, that is stored to be retrived and used later, saving a new request to the server. Ex: GET, HEAD, POST(Only if freshness information is included),
Features | POST | GET | PUT | DELETE | PATCH | TRACE | OPTIONS | CONNECT | HEAD |
Safe | No | Yes | No | No | No | Yes | Yes | No | Yes |
Idempotent | No | Yes | Yes | Yes | No | No | Yes | No | Yes |
Cacheable | No | Yes | No | Yes | No | No | No | No | Yes |
Subscribe to my newsletter
Read articles from Vineesh Chauhan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
