Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Understand what an HTTP Response is


    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.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    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.

    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.

    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.

    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.

    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.

    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.

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