Understand what an HTTP Response is

Pete Johanson
InstructorPete Johanson

Share this video with your friends

Send Tweet
Published 5 years ago
Updated 3 years ago

Let's look at several HTTP responses to learn the basic structure of these messages, and how the various elements communicate important information from the API service to the client/browser.

[00:02] We're going to use HTTPI to construct some HTTP response headers and bodies. Here we'll do an HTTP Get on http://google.con. HTTP responses are structured very similarly to HTTP requests. In particular, the first line is the only area where the two differ. The response is made up of a HTTP status line, a set of HTTP headers, and an optional response body.

[00:30] Let's take a look at that first line. The first piece of our status line indicates the specific HTTP version that's being used in our response. The next two pieces indicate the same information, one with a numeric status code, the other with a textual representation of that same status code.

[00:52] Here we can see that google.com is responding with a 301 response, indicating that this resource has moved permanently. From looking at this location header, we can see that they really want us to go to www.google.com. Let's take a look at the response when we visit there.

[01:09] Here we can see our response has a much larger response body. We can see that we, instead, have a status code of 200, indicating OK, it was successfully retrieved from www.google.com/resource. Along with our response headers, we have a response body, also in text HTML format.

[01:33] Along with the 301 and 200 status codes, we can also see a status code if we try to request a resource that doesn't exist. We use api.github.com/users/thisisreallynotarealuser, and here we can see our status code is 404 Not Found.

[01:55] Even though our resource was not found, we still get back some response headers, as well as a message body, in this case, the message body indicating the error message, not the actual response body for the actual resource we were looking for.

[02:08] To review, our response is structured with a status line, a set of HTTP response headers, and an optional response body.