Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
How the Internet Works  ›  Lesson

HTTP — Asking and Answering

What is HTTP? 14 minHTTP is the request and response conversation of the web: the browser sends a method and a path, and the server replies with a status code, headers and a body.

HTTP — Asking and Answering

Packets can carry anything, so the browser and the server need an agreed way to say "please send me the menu page" and "here it is". That agreement is HTTP, the HyperText Transfer Protocol. Every page, image, stylesheet and script on the bakery site arrives through an HTTP conversation.

The rule

The browser asks with a method and a path; the server answers with a status.

An HTTP request is plain, readable text. Opening the bakery's menu sends something like this:

GET /menu HTTP/1.1
Host: crumbbakery.com
Accept: text/html
  • Method (GET): what you want done. GET fetches, POST sends new data such as an order form, PUT and PATCH update, DELETE removes.
  • Path (/menu): which thing on the server.
  • Headers (Host, Accept): extra details, one per line, as Name: value.

The response comes back in the same shape:

HTTP/1.1 200 OK
Content-Type: text/html

<!DOCTYPE html>
<html>...the menu page...</html>

The number is the status code, and its first digit tells you the story:

Class Meaning Examples
2xx It worked 200 OK, 201 Created
3xx Look somewhere else 301 Moved Permanently, 304 Not Modified
4xx The request was wrong 404 Not Found, 401 Unauthorized, 403 Forbidden
5xx The server failed 500 Internal Server Error, 503 Service Unavailable

HTTP is stateless: each request stands alone, and the server does not automatically remember the previous one. Sites remember who you are by sending something with every request, most often a cookie.

HTTPS is the same conversation wrapped in encryption (TLS), so nobody on the path can read or quietly change it. Today every public site should use it.

The shortcut

Read any request or response with the "verb, noun, verdict" pattern: the method is the verb, the path is the noun, the status code's first digit is the verdict. 4 means "you asked wrongly", 5 means "I broke".

A customer places an orderStep 1 of 4
  1. Verb and noun

    The order form sends POST /orders: create something new in the orders collection.

Watch for the classic mix-up: a 404 is the client's problem (wrong address), while a 500 means the server's own code crashed. Fixing a 500 by retyping the URL will not help.

Drills

Answer fast — trust the rule.

quick drill

Which method should the bakery's order form use to send a new order?

quick drill

A visitor types crumbbakery.com/menuu and gets a status in the 400s. Most likely which one?

quick drill

What does a status code starting with 5 tell you?

quick drill

HTTP is stateless. How does a site still know you are logged in on your next request?

Remember

  • The browser asks with a method and a path; the server answers with a status.
  • Verb, noun, verdict: 2 worked, 3 look elsewhere, 4 you asked wrongly, 5 the server broke.
  • Trap: HTTP forgets between requests, so cookies carry who you are.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainReading the verdict

A visitor reports two problems: the page crumbbakery.com/cakes shows 404, and submitting the order form shows 500. Explain what each code means, whose side the problem is on, and what request method the order form should use.