Let's take a closer look at HTTP. In this lesson, we'll examine the organization and data of HTTP requests.
When the client triggers a new HTTP request, the request includes four elements that will be sent to the server:
HTTP methods, also known as verbs, indicate the kind of action that the client is requesting be done in the server. The two most frequently used methods are the ones that are supported by all browsers: GET and POST. A request with a GET method indicates that a resource is being retrieved. A request with a POST method indicates that the resource is being changed - possibly added, updated or deleted.
An example of a GET request is when we navigate to the Learn How to Program Courses page. The client requests the resource at the URL,
http://www.learnhowtoprogram.com/courses and the
/courses resource(s) is retrieved.
An example of a POST request is when we click submit on a form to add our email to a mailing list. The message would post data to the server by adding our information to the mailing list resource.
The path identifies the web resource that should be retrieved (GET) or acted upon (POST). In our example,
http://www.learnhowtoprogram.com/courses, the resource
/courses is known as the path.
Request headers are part of the request message protocol and provide the server with more information about the client, the server and the request.
Here are some examples of header fields that are included in a request message:
For a list of all request headers that may be sent in a request, see here.
The body contains data beyond the contents of the URL and headers that needs to be transmitted to the server. For example, if a user submits a form with data, the resulting POST request would need to include all of the data inputted so the server could store the information. This data is delivered in the body of the request.
HTTP Method: The kind of action that the client is requesting to be done in the web server, also known as a verb. Most frequently used HTTP methods:
GET: A request method that retrieves information from the server but does not change anything on the server. Example: request to see a homepage for a site.
POST: A request method that acts upon the resource by adding, updating or deleting information on the server. Example: submitting a form to join a mailing list which adds your name to the list.
HTTP Request Header: The first lines of an HTTP request message that include information about the client, server and the request. Common headers include Host, User-agent, and Accept-language.
HTTP Request Body: Data that needs to be transmitted to the server in the HTTP request message (like data from a submitted form).