Your First Request
Lesson 4 of 47 in Coddy's Networking with the Terminal course.
Enough theory. You are going to be both ends of a conversation: start a server, then ask it for something.
Python ships with a tiny web server. Point it at a folder and it serves the files there:
python3 -m http.server 9101 &The & at the end matters. It puts the server in the background so you get your prompt back. Without it the server would hold the terminal and you would have nobody to type the request.
Now the client side. curl is a command that makes a request and prints the answer:
curl -s http://127.0.0.1:9101/hello.txtThe -s means silent. Without it, curl prints a progress meter that gets in the way of the actual response. Get into the habit now: in this course, curl always gets -s.
Read that address from the left. http:// is the language being spoken, 127.0.0.1 is the machine, 9101 is the port, and /hello.txt is what is being asked for. The next chapters take those apart one at a time.
Challenge
EasyBe both ends of a request, start to finish.
- Create a file called
hello.txtcontaining exactlyhello from your first server - Start Python's web server on port 9101 in the background
- Fetch
http://127.0.0.1:9101/hello.txtwithcurl -s
A server takes a fraction of a second to come up. Run
sleep 1after starting it, or your request may arrive before anything is listening.
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
Practice on your own: Terminal playground