POST vs GET in HTML forms – when and why to use

POST vs GET in HTML forms – when and why to use

POST vs GET – this is a very common question among beginners in the web industry. Out of the basics of HTML that we learn in the very beginning of our web design learning curve, forms are a typical mandate.

HTML forms have a very important significance. Forms are a method to capture user feedback and response, and they have been in use since the early days and up until today.

Anyways, we will see in this article how we can define HTML form submission methods POST vs GET, and when and why they should be used.

HTML form submission methods – an overview

Form data can be submitted using two defined methods – HTTP GET and HTTP POST. These methods are two of the methods used in the REST architecture of the World Wide Web.

HTTP, or Hyper Text Transfer Protocol is a mechanism with which data transfer is made possible in a client-server architectural system.

Suppose you are the client, using your laptop and querying a search term in Google’s homepage. So, the system (or server) that hosts Google will be the server in this architecture.

You type in a term and press enter on the form Google provides. This is then carried by the HTTP request to the server end and an apt response (along with the request details) is sent back from the server side.

HTTP POST vs GET – some usage examples

The GET method is used in forms that carry general (non-sensitive) data. This data, even if disclosed to a third party, should not be enough harmful for the client.

Some examples of using GET in forms would be – searching for a keyword in Google, searching a video on YouTube, searching for a hashtag on Twitter, etc.

On the other hand, the POST method is used when you want to pass some secret, sensitive data to the server end. This data must not be disclosed by any means.

Some examples of using POST in forms – Filling up a user details form including password field, form for logging into your bank website, logging into your email client inbox, etc.

POST vs GET – complete comparisons.

Decide which method your form should use in order to meet your required criterion. An interesting comparison between HTTP POST vs GET is provided here, you might take a look.

I have provided an overview of all the differences. Take a look at the following. This will give you a better idea –

Features of the GET method –

  1. GET method appends all form data in name/value pair format within the URL while passing data to the server. So, all data is visible.
  2. When we refresh a page or press the back button, this does not affect GET method submitted data.
  3. The length of an URL is limited, so GET data transfer also becomes limited (3000 characters)
  4. Good for non-sensitive data.
  5. GET request data has the provision of caching.
  6. GET request data gets stored and remains in browser history.
  7. Bookmark of GET submitted data is possible.

  Features of the POST method –

  1. POST encodes the form data into the HTTP request body. Thus, saving it from hacking or third party attacks.
  2. No size limitations.
  3. Also, maybe used for sensitive data; since data becomes embedded inside HTTP request body and becomes invisible.
  4. Pressing back button or refresh causes the data to be re-submitted. This should be stopped as this might cause duplicate data issues at the server end.
  5. Caching not possible.
  6. Data submitted using POST cannot be bookmarked for future usage.

So, now you know all about using POST vs GET. You can keep this POST vs GET analysis handy next time when you create forms and implement submission methods. This guide will help you decide better.

Comments are closed.