Backend Developer

Case File: The Route Table

A new parcel service must decide, for every request, what the server says back. Write the handler that finds the route, refuses a wrong method with a list of the right ones, tells a stranger from a person who is not allowed, and answers success with the right code. Check it on request lists you cannot see. The routes and tokens are generated for you alone.

50 min

Sabi Logistics · Backend 1

The Route Table

The mobile app shows Something went wrong for every error, because our server answers 200 or 500 and nothing in between

Chidi Engineering manager ·

Chidi. The new mobile app has one error message: “Something went wrong”. Our server only ever says 200 (fine) or 500 (broken), so the app cannot tell a wrong address from a missing login from a bug, and support is flooded.

I want a proper handler. Given a request (a method, a path and maybe a token), it must say which thing is wrong, with the right HTTP status, in a fixed order, so that the app can show the right message and so that we can test it. Here are the routes and the tokens. Please write the handler and run it on the requests.

The brief

What you need to know first.

  • A route is a method plus a path pattern. /parcels/{id} matches /parcels/42 (digits only) but not /parcels/abc. A trailing slash makes a different path, so /parcels/42/ is not found. Split the path after the first slash and compare the parts one by one.
  • The order of the checks is the whole lesson: first the path (no route: 404), then the method (a route exists but not for this method: 405, with the allowed methods in alphabetical order), then who you are (no token or an unknown token: 401), then what you may do (a known token whose role is too low: 403), and only then success (200, 201, 204).
  • 401 and 403 are different. 401 means “I do not know who you are”: log in. 403 means “I know who you are, and you may not”: asking again will not help. Mixing them up sends users to the login page for a problem that a login cannot fix.
  • Roles. A dict of levels (user is 1, admin is 2) lets you compare roles with a number: a token is good enough when its level is at least the level that the method needs.
  • Write match(path), handle(req) and handle_all(reqs); fill in results and by_status (the count of each status, with the status written as text). The checks run handle_all on lists you cannot see.

The lab gives you the data for this case, invented and generated for you alone. Today is 2026-11-09.

Preparing your data…

On a real system

The lab modelled the rules with a script. These are the commands that you would type on the real thing.

You want toTypeWhat you get
see the status line and headers of a responsecurl -i -X DELETE http://localhost:8000/parcels/7the status (401, 403, 404, 405 and so on) and headers such as Allow
print only the status codecurl -s -o /dev/null -w "%{http_code}\n" http://localhost:8000/healthjust the number
send a token with a requestcurl -H "Authorization: Bearer t-abc123" http://localhost:8000/parcelsthe answer for a logged-in caller

Only run commands on systems that you own or have written permission to test.

🔒 The debrief unlocks when you close the case. Finish the lab above.

Write the handler note

Write the note for the engineering manager: the order of the checks and why (route, method, token, role, success), what each status means and the difference between 401 and 403, what the 405 answer must include, which statuses your handler gave in the sample and how often, what an error body should contain, and what you would test so that the order cannot change by accident.

0 words

🧪 Want to practise this on your own computer? See how to set up your lab →

📝

Knowledge Check

1 of 4

A user is logged in but is not allowed to delete a parcel. Which status is right?

Report a problem

About: /lessons/case-the-route-table