Request Methods
Lesson 21 of 47 in Coddy's Networking with the Terminal course.
The method says what kind of operation you want. Four cover almost everything:
- GET: give me this thing. Changes nothing.
- POST: here is some data, do something with it.
- PUT: store this, at this exact place.
- DELETE: remove it.
GET is safe: it should never change anything on the server, which is why a browser can fetch a page twice without asking permission. That is also why a link that deletes something is a design mistake, since anything that follows links may trigger it.
A server is free to refuse a method it does not implement, and it says so with a status code rather than an error message. Python's simple file server, for instance, understands GET and HEAD and nothing else.
curl sends GET unless told otherwise. -X changes the method.
Challenge
MediumAsk a server to do something it does not support, and read its answer.
Python's file server understands GET and HEAD only. Serve a folder on port 9111, then send it a POST and print just the numeric status code it replies with.
Expected output:
501501 means "not implemented".
-o /dev/nullthrows away the body and-w "%{http_code}"prints the code.
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