⚠️ This lesson is retired and might contain outdated information.

Understand what an HTTP Request is

Pete Johanson
InstructorPete Johanson

Share this video with your friends

Send Tweet
Published 7 years ago
Updated 6 months ago

Let's look at several HTTP requests to learn the basic structure of these messages, and how the various elements communicate important information from the client/browser to the API service. Follow the instructions at HTTPie to download the CLI tool and follow along.

[00:01] I'll be using HTTPI to inspect some HTTP requests. Visit httpie.org and follow the instructions to install it for your operating system. First, we will inspect the request headers and body, and do a get request on api.github.com/users/petejohanson.

[00:26] These are the key elements of an HTTP request. Our first line, a set of request headers, and then an optional request body. Let's take a look at our first line. The first element of our first line is the HTTP method.

[00:43] In this particular instance, I did and HTTP get, and that's reflected in our request. If, instead of doing an HTTP get, I issued an HTTP options request, that change would be reflected in our new request here. There are standard HTTP methods, such as put, post, and delete, which all have different semantic meaning for what you want to do in interacting with a particular location.

[01:11] The second portion of our first line is the path and queries string for our URL. You can see, since we visited api.github.com/users/petejohanson, that path is reflected in our first line right here. If we had, instead, changed our path from petejohanson to /users/eggheadio, we would see that new path reflected in our second piece of our first line.

[01:39] The final portion of our first line indicates the specific HTTP version used in our request, in this case HTTP 1.1. After our first line, there are a set of HTTP request headers. Headers are formatted as a header name, a colon, and the header value.

[02:02] The headers indicate various options and aspects of a request that will affect how the server can respond to a request, such as what file types we would like to accept and which hubs we are trying to make our request to.

[02:15] Following our HTTP request headers is an optional request body. Let's make another request, and we'll use the HTTP put method here along with some form parameters. Here we can see, in addition to our first line and our headers, we now have our request body represented.

[02:38] In addition to our form parameters that have been placed in our request body, we have a few new HTTP request headers as well, indicating the length of our content, as well as the type of our content, in this case, some form URL encoded parameters.

[02:56] If we had used, instead of form encoding, JSON encoding, we can see that our request body would be JSON. In addition to the changes, our content length, and our content type, we update it to reflect our new request body content type.

[03:15] To summarize, we have our first line with our method, our path and query parameters, a set of request headers, and then an optional request body.