CoursesBackend engineering from first request to production
Puzzle 0 · 1 of 18
What happens when a client sends a request?
Follow one bookmark from a client to the process that owns it.
All puzzles in this course
The problem
A client is a program asking another program to do something. A server is the program receiving that request. Both can run on your own computer. If you ask it to save a bookmark called river, which program owns the result?
See it
Scroll sideways to see the full diagram.
The client asks to save river.
Step 1 of 4A process accepts the connection.
Step 2 of 4The handler matches the write path.
Step 3 of 4The server confirms creation.
Step 4 of 4
The building block
A route pairs a request method and path with the code that handles it. Hypertext Transfer Protocol (HTTP) is the set of rules the programs use for requests and responses. The method names the action. The path identifies the requested resource. A port is the number the operating system uses to deliver the connection to the listening program. Start the lab server in one terminal. In another, send the first write from the lab guide. The server listens on port 8080. Its handler receives the method and path and checks the name. A status code is a number describing the outcome. A valid write returns a status and the saved name. Change only the path to /unknown. The server can answer 404 because the request reached it. Stop the process and repeat. Now the client cannot connect to that port, so there is no response status.
Follow a read before attempting a write
The client asks to read the list. Its request line names the read method and the /bookmarks path. The listener accepts the connection, finds the read route, reads one stored name and sends status 200 with a list containing river. Change only the path to /missing and keep the server running. The connection succeeds again, but the response is now 404. Stop the server and repeat on the same port. This time there are no HTTP response bytes to inspect. Work from the outside inward: was there a connection, was there a response, and what does its body say?
Try it
Optional local lab
Compare the wrong-path response with the stopped-process result. Save both outputs.
Check yourself
Sources
What you now know
A route matches the method and path before a handler runs.
Answer every question above correctly to unlock the next puzzle.
Something wrong or unclear on this page? Tell me: a puzzle that didn't click is a bug in the puzzle.