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

Understand what an HTTP Response is

Pete Johanson
InstructorPete Johanson
Share this video with your friends

Social Share Links

Send Tweet
Published 8 years ago
Updated a year 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.

egghead
egghead
~ 20 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today