.NET Academy

Anatomy of an HTTP request

What a browser actually sends to a server, and what comes back.

10 min read

You will learn

  • Read a raw HTTP request and response line by line
  • Know what GET, POST, PUT, PATCH and DELETE are for
  • Group status codes into their five families
  • Understand why HTTP is called "stateless"

Clients and servers talk in HTTP

Every time you open a web page, submit a form or an app loads data, a client (browser, mobile app, another server) sends a request to a server, and the server sends back a response. The rules for that conversation are HTTP — the HyperText Transfer Protocol.

The surprising part: HTTP messages are just plain text in a fixed format. Once you can read them, debugging backends gets much easier.

The request

Here is a real request a browser might send to create a to-do item:

POST /api/todos HTTP/1.1
Host: example.com
Content-Type: application/json
Accept: application/json
Authorization: Bearer eyJhbGciOi...
 
{"title": "Learn HTTP", "done": false}

It has three parts:

  1. Request line — POST /api/todos HTTP/1.1: the method (what to do), the path (which resource), and the protocol version.
  2. Headers — Name: value lines with extra information: which site (Host), the body format (Content-Type), the format we'd like back (Accept), who we are (Authorization).
  3. Body (optional) — the data being sent, separated from the headers by an empty line. GET requests usually have no body.

Methods: the verbs of HTTP

MethodMeaningExample
GETRead a resourceGET /api/todos/7
POSTCreate a new resourcePOST /api/todos
PUTReplace a resource entirelyPUT /api/todos/7
PATCHUpdate part of a resourcePATCH /api/todos/7
DELETERemove a resourceDELETE /api/todos/7

GET must never change data

Browsers, proxies and search-engine crawlers assume GET is safe to repeat or prefetch. A "delete" link implemented as GET /delete?id=7 will eventually delete things nobody meant to delete.

The response

HTTP/1.1 201 Created
Content-Type: application/json
Location: /api/todos/42
Date: Tue, 06 Oct 2026 10:15:00 GMT
 
{"id": 42, "title": "Learn HTTP", "done": false}

Same shape, different first line: the status line contains a status code (201) and a human-readable reason (Created). Then headers, an empty line, and the body.

Status codes: five families

The first digit tells you who's "at fault":

RangeFamilyCommon codes
1xxInformational101 Switching Protocols (WebSockets)
2xx✅ Success200 OK, 201 Created, 204 No Content
3xx↪️ Redirect301 Moved Permanently, 304 Not Modified
4xx🙋 Client error400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found
5xx💥 Server error500 Internal Server Error, 503 Service Unavailable

401 vs 403

401 Unauthorized really means "I don't know who you are" — log in. 403 Forbidden means "I know who you are, and you're not allowed".

HTTP is stateless

Each request stands on its own. The server doesn't automatically remember that you sent a request a second ago. If it needs to know who you are, every request has to say so — usually with a cookie or an Authorization token in the headers.

Statelessness is a feature: any server in a cluster can handle any request, which is what makes backends easy to scale. You'll see this idea again in the Performance & scaling and Auth & security modules.

Try it

Send requests to a small mock API. Try the presets, then experiment: remove the Content-Type header from a POST, send invalid JSON, or use the wrong method on a URL.

Interactive

HTTP Playground

Send requests to a mock todo API at https://api.example.com — it runs in your browser

Server state: 2 todos — #1 ✓ Learn HTTP, #2 ○ Build an API

How this maps to .NET

In ASP.NET Core (Track 11), you describe what to do for each method + path, and the framework handles the raw text for you:

app.MapPost("/api/todos", (Todo todo) =>
    Results.Created($"/api/todos/{todo.Id}", todo));   // → 201 Created + Location header

Key takeaways

  • A request = method + path + headers + optional body; a response = status code + headers + optional body.
  • Use methods for their meaning: GET reads, POST creates, PUT/PATCH update, DELETE removes.
  • Status code families: 2xx success, 3xx redirect, 4xx client mistake, 5xx server problem.
  • HTTP is stateless — identity travels with every request.

Quiz

4 questions · 3 correct to pass
  1. 1.A client wants to create a new order. Which method fits best?

  2. 2.The server responds with 404. What does that mean?

  3. 3.Which header tells the server what format the request body is in?

  4. 4.What does it mean that HTTP is stateless?

To complete this lesson

  • ○ Pass the quiz (3/4 correct)