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.
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.
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.
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.
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.
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.
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.
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.
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.
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.