API Fundamentals Course
API Fundamentals
/
Intermediate

HTTP Request Structure

Definition

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

Explain Like I'm New

Sending an HTTP request is like mailing a letter. 1. The Request Line is the address on the envelope (Where is it going?). 2. The Headers are the stamps and metadata (First-class mail, sent from New York). 3. The Body is the actual folded letter inside the envelope (The data you are sending).

Real World Example

Submitting a Login Form. The Request Line says 'Send this to /login'. The Headers say 'This is JSON data'. The Body contains `{ "email": "test@test.com" }`.

Common Use Cases

  • •Debugging network traffic
  • •Building API clients

Anatomy of an HTTP Request

ComponentPurposeExample
Method (Verb)Defines the action you want to perform (e.g., Get data, Create data).`GET`, `POST`, `PUT`, `DELETE`
URL (Endpoint)The specific web address you are sending the request to.`https://api.github.com/users`
HeadersHidden metadata sent with the request (authentication tokens, content types).`Authorization: Bearer xyz123`
Body (Payload)The actual data being sent to the server (Usually in JSON). Not used in GET requests.`{ "username": "alice" }`

Interactive Example

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

Interview Questions

basic

  • What are the three main components of an HTTP Request?

intermediate

  • Does a standard `GET` request (like simply visiting a webpage) usually have a Request Body?

Flash Cards

Question

Three components?

Click to reveal answer
Answer

Request Line (Method + URL), Headers (Metadata), and the Body (Data payload).

Question

GET request body?

Click to reveal answer
Answer

No. GET requests are strictly for 'getting' information, not sending large payloads of data. All necessary data in a GET request is usually appended to the URL as query parameters (e.g., `?search=shoes`).