HTTP Methods: Get? Post? What does it mean?
Published: 2020-08-31 13:45:18

Let's take a moment to discuss what happens when a user visits a website, in particular how the data that is ultimately seen by a user get to their browser.  It turns out that the majority of the content of the webpage is the result of a a data transfer called Hypertext Transfer Protocol (HTTP). 

Take a look at the URL above.  It probably starts with http://.  What is this mysterious transfer protocol? Well, according to [w3schools.com](https://www.w3schools.com/tags/ref_httpmethods.asp), "HTTP works as a request-response protocol between a client and server."  As an over-simplified illustration of this concept, think about logging into Facebook or YouTube.  When the user logs in with their credentials, the browser (the client) sends a request for data associated with that user from the computers responsible for running YouTube (the server).  When the server sends back that data, the page is reloaded with the appropriate information (the username, the history feed, recommendation feed, etc). The users computer client and the service's server has a conversation.  The client tells the server "Hi, my name is Chris, may I have my data? My password is Password123" (side note, please do not use a simple password like Password123).  If everything checks out and the server recognizes the information given to it by the client, it will fulfill the request and send the appropriate data to the client. Of course, the technical side of things is a tad more complicated.


With the core concept of HTTP covered, let's discuss the different possibilities presented to the developer with regards to HTTP methods and when to use each. With regard to the many different options, the two most frequently used methods are GET and POST.  According to [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET), "the HTTP GET method requests a representation of the specified resource" and importantly these requests "should only retrieve data." In the above sign-in example, the client is sending a GET request asking for the user's watch history, profile information, etc.  A get method with the following URL should return the appropriate information associated with user 'Chris.'
`http://my-amazing-website-name.com/api-name/users/chris`

Receiving data is one thing, but how about sending data out to the server?  That's where the POST command comes in. Taken from MDN, "the HTTP POST method sends data to the server ... [and] is typically sent via an HTML form and results in a change on the server." A simple illustration of this is to think of posting a message on a community forum such as Reddit. When a user submits a new post, it is sent to the server in the form of a POST request.

Finally what about the possibility of deleting data from a server? Such as deleting a post from the community forums or deleting an account altogether? HTTP has developers covered. Our last command today is the DELETE method.  According to [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE), the DELETE method does exactly what can be inferred from the name: DELETE "deletes the specified resource." For instance, when a user of instagram decides to delete their post, the delete command is run and removes the appropriate data from the server.

That about wraps it up for the most common HTTP methods developers have in their arsenal. There are several others in existence and maybe I will cover them at a later date.