API Fundamentals Course
API Fundamentals
/
Intermediate

HTTP Response Structure

Definition

The specific format of the message sent from the server back to the client. It consists of a Status Line, Headers, and an optional Body.

Explain Like I'm New

The server's reply to your letter. 1. Status Line tells you instantly if it succeeded or failed ('200 OK' or '404 Not Found'). 2. Headers tell the browser how to read the data ('This is an image', 'Cache this for 1 hour'). 3. The Body is the actual webpage, image file, or JSON data.

Real World Example

A server returning a successful login attempt. The status line is `200 OK`. The headers include a `Set-Cookie` command to keep the user logged in. The body contains the user's profile data.

Common Use Cases

  • •Parsing API responses
  • •Error handling

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • What is the first line of an HTTP Response called?

intermediate

  • If a server returns an image file, how does the browser know it's an image and not a text file?

Flash Cards

Question

First line called?

Click to reveal answer
Answer

The Status Line (which contains the Protocol Version, Status Code, and Status Text).

Question

How does browser know?

Click to reveal answer
Answer

Because of the `Content-Type` Header in the HTTP Response. If it says `image/jpeg`, the browser renders a picture. If it says `text/html`, it renders a webpage.