HTTP in Five Minutes2013-07-14
A request refers to when a web browser(e.g. Chrome, Firefox, Internet Explorer, etc.) requests a web page(Note: This isn’t 100% accurate. Requests are not made only from internet browsers, but for a basic understanding this explanation will suffice). Think of it as though every time you either enter a URL and go to a web page, click on a link to a webpage, etc. you have just sent a request for that webpage. Here’s what your request looks like when you type in “www.google.com” and go:
A request is a couple lines of text that describes to a server what resource(s) you are trying to access. Think of it as though you’re going to a library and telling the librarian that you want to access the book stored at the location “slash” under “www.google.com”. The above request is going to the “google.com” domain, under the “www” subdomain for a document located at the path “/” and is using HTTP version 1.1.
There are a few different methods that are used in the HTTP protocol. In the above request we were using GET. GET simply means we are requesting the information stored at a certain location(“GET me that book!”). Another common method is POST, which is used when we want to send some information back to the server. For instance when you fill out a form and submit it on a web page you are typically sending a POST request. The POST request tells the server where to store the information you are sending it. There are a handful of less commonly used methods(roughly descending in order) such as HEAD, PUT, DELETE, TRACE, OPTIONS, and PATCH. For our understanding you won’t need to worry about these methods.
The server, if it could be found, will respond with the information, if it could be found(or with an HTTP 404 error if the resource could not be found). In the case of the request we sent above, the response from google will look something like this:
The server found the resource/document(HTTP Status Code 200) and the it is text/html. Below the header of the response is the document, written in HTML. Assuming you’re using a web browser, the webpage shown above will be rendered in your browser. To continue with the library metaphor, this is a librarian handing you the book it found at “slash” under “www.google.com”(Hopefully there aren’t too many libraries like this).