HTTP Methods

HTTP (Hypertext Transfer Protocol) is created to provide communication between clients and the server. It works as request and answer.

There are two mostly used HTTP methods: GET and POST:

GET Method

HTTP's GET method requests data from a specified source. GET requests can be cached and remain in the browser history. It can also be bookmarked.

It should never be used while working on sensitive data. GET requests have length restrictions and they should be used only to get data.

The query strings (name/value pairs) is sent in the GET request's URL.

The code will look like this:

<form  method="get">
     First name: <input type="text" placeholder="Your name"><br/>
     <input type="submit" value="Submit">
</form>

POST Method

The POST method submits data to be processed to a specified source. In opposition to GET method, POST requests are never cahched and they don't stay in the browser history and we cannot bookmark them. Moreover, POST requests have no data length restrictions.

The query strings (name/value pairs) is sent in the POST request's HTTP Message body.

The code will look like this:

<form  method="post">
     First name: <input type="text" placeholder="Your name"><br/>
     <input type="submit" value="Submit">
</form>

Comparison of GET and POST Methods

GET POST
Back button/Reload Harmless It means that the data will be resubmitted. The browser must warn that the data will be re-submitted in this case.
Can be Bookmarked Yes No
Can be cached Yes No
Encoding Type application/x-www-form-urlencoded application/x-www-form-urlencoded or multipart/form-data
History Remains in the browser history. Doesn't remain in the browser history.
Data Length Restrictions While sending data, GET method adds the data to the URL; and the URL length is limited (maximum URL length is 2048 characters). Doesn't have restrictions.
Data Type Restriction Only ASCII characters allowed. Doesn't have restrictions. Binary data is also allowed.
Security It is less secured than POST as data sent is a part of URL. POST is a little safer than GET as it is not remaining in the browser history or web server logs.
Visibility Data is visible to everyone in the URL. Doesn't show data in the URL.

Other HTTP Request Methods

Beside GET and POST methods, there are some other methods. See them below:

Method Description
HEAD It is same with GET method but it returns only HTTP readers, no document body.
PUT It uploads the specified URI's representation.
DELETE It deletes the specified resource.
OPTIONS It returns HTTP methods which are supported by the server.
CONNECT It converts request connection to a transparent TCP/IP tunnel.