Skip to content

Instantly share code, notes, and snippets.

@ryanswood
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save ryanswood/9494786 to your computer and use it in GitHub Desktop.

Select an option

Save ryanswood/9494786 to your computer and use it in GitHub Desktop.

#What is the difference between GET and POST?

The HTTP verbs GET and POST are both actions that relate to the clients request in the request/response cycle. The response is not a consideration of GET and POST.

Imgur

##Let's first look at the technical definitions of each:

###GET

####Get W3.org Http1.1 Protocol:

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.

####Wiki:

Requests a representation of the specified resource. Requests using GET should only retrieve data and should have no other >effect.

###Post ####Wiki

The POST request method is designed to request that a web server accept the data enclosed in the request message's body for >storage.[1] It is often used when uploading a file or submitting a completed web form.

##Difference anaylsis:

The submission process for both methods begins in the same way - a form data set is constructed by the browser and then encoded in a manner specified by the enctype attribute.

The HTML specifications technically define the difference between "GET" and "POST" so that former means that form data is to be encoded (by a browser) into a URL while the latter means that the form data is to appear within a message body.

The HTML specifications suggest: If the processing of a form is idempotent (i.e. it has no lasting observable effect on the state of the world), then the form method should be GET. Many database searches have no visible side-effects and make ideal applications of query forms.

Whereas, "POST" may involve anything, like storing or updating data, or ordering a product, or sending E-mail. Any information is meant to be kept hidden, such as a login form with a username and password.

##Suggestion:

GET is recommended when submitting "idempotent" forms - those that do not 'significantly alter the state of the world'. In other words, forms that involve database queries only. Just remember that the information sent in the url is visible and often cachable. You do not want to send out private information.

POST usage is recommended if the database updates or triggers another action that affects change. The one exception to the rule is if the idempontent form is very large. Post can better handle a larger data set.

##Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment