Introduction to HTTP Request Methods

Introduction to HTTP Request Methods

ยท

3 min read

What is HTTP ?

๐Ÿ‘‰ The Hypertext Transfer Protocol (HTTP) is designed in such a way that it can create a communication between between clients and servers.

๐Ÿ‘‰ HTTP works as a request-response protocol between clients and servers and follows the old classical client-server model.

Request-Response Overview

1_8-fT6K1o6nHiBRxKppcqOg.png

๐Ÿ‘‰ The client (browser) sends a HTTP request to the server. Then the server returns a response to the client.

Get()

๐Ÿ‘‰ Get method is used to get data from a specific server using a URL.

๐Ÿ‘‰ It is only used to request and retrieve data from a specific resource

Get  /index.html

Post()

๐Ÿ‘‰ Post method is used to send data to a server for creation/updating of a resource

๐Ÿ‘‰ The data sent to the server with post method is stored in the request body of the HTTP request

POST /test HTTP/1.1
Host: foo.example
Content-Type: application/x-www-form-urlencoded
Content-Length: 27

field1=value1&field2=value2

Put()

๐Ÿ‘‰ Post method is also used to send data to a server for creation/updating of a resource

๐Ÿ‘‰ Difference between Put and Post method is Put requests are idempotent, that is invoking the same Put request would always produce the same result.

๐Ÿ‘‰ But Successive Identical Post would have additional side effects to the server.

PUT /new.html HTTP/1.1
Host: example.com
Content-type: text/html
Content-length: 16

<p>New File</p>

Head()

๐Ÿ‘‰ Head is almost similar to Get method, but it does not have any response body unlike Get method.

๐Ÿ‘‰ Head method is used to check the Get method response before making the actual Get request.

HEAD /index.html

Delete()

๐Ÿ‘‰ The HTTP Delete method is used to delete a specified resource

DELETE /file.html HTTP/1.1

Patch()

๐Ÿ‘‰ The HTTP Patch request method is a set of instructions which is used for partial modification of a specific resource.

๐Ÿ‘‰ Unlike Put methods, the Patch request method may or may not be idempotent.

๐Ÿ‘‰ It may produce side effects to the server.

PATCH /file.txt HTTP/1.1

Options()

๐Ÿ‘‰ The Options request method mainly provides communication options for a specific resource

๐Ÿ‘‰ A client can specify a URL or an asterisk (*) with this method to refer to the entire server.

OPTIONS /index.html HTTP/1.1
OPTIONS * HTTP/1.1

Connect()

๐Ÿ‘‰ The Connect method is used to start a two-way communication tunnel with the requested resource.

๐Ÿ‘‰ The Client asks the HTTP server to tunnel the TCP Connection to the desired destination.

CONNECT www.example.com:443 HTTP/1.1

Trace()

๐Ÿ‘‰ The Trace method is used to perform a message loop-back test which test the path of the target resource.

๐Ÿ‘‰ It also provides a useful debugging mechanism.

TRACE /index.html

If you liked my content, connect with me? ๐Ÿ˜ƒ

github linkedin twitter

ย