Recap: HTTP Basics
Lesson 25 of 47 in Coddy's Networking with the Terminal course.
HTTP is text in a fixed shape, both ways.
A request is a method, a path and a version, then headers, then a blank line, then an optional body. A response is a version and a status code, then headers, then a blank line, then the body.
The method says what kind of operation: GET reads and must be safe, POST submits, PUT stores, DELETE removes.
The status code says how it went, and the first digit assigns blame: 2xx worked, 3xx go elsewhere, 4xx your request was wrong, 5xx the server broke.
The headers describe the body, above all Content-Type. And every one of those pieces is something you can type by hand, which is worth remembering the next time HTTP feels like magic.
Challenge
ExpertRead a whole response, top to bottom, from a server you wrote yourself.
Serve a hand-written response on port 9115 whose status line is HTTP/1.1 404 Not Found, with a Content-Type: text/plain header and the body nothing here. Then use curl to print the status code and, on the next line, the body.
Expected output:
404
nothing hereEach
nc -lserves one client and exits, so start a second one before the second request.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Networking with the Terminal
5HTTP by Hand
Anatomy of a RequestRequest MethodsStatus CodesResponse HeadersWriting a ResponseRecap: HTTP BasicsPractice on your own: Terminal playground