Lab · Backend Development
Lab: a complaints API for a housing society
The brief
Residents of Green Valley society in Thane raise complaints from an app: no water, the lift is stuck, a light is out. Build the API behind it, step by step: match routes with path parameters, list complaints with a filter, create one with validation, send each request to the right handler, and turn crashes into a clean 500.
Why it matters
Society-management apps like MyGate and NoBrokerHood, and almost every business API, are made of exactly these parts. Express does the routing for you, but interviewers still ask how routing works, which status code to return, and how to validate input and handle errors.
Skills you practise
- path parameters
- query strings
- input validation
- status codes 200, 201, 400, 404, 405 and 500
- a routing table
- error handling
What you will have at the end
complaints.js: a small, tested complaints API (routing, listing, creating, error handling) for a housing society app.
How it is marked (rubric, 100 points)
| Correct behaviourEvery check passes: right handlers, right status codes, validation and the 500 guard. | 45 |
|---|---|
| Right status codesYou can explain 200, 201, 400, 404, 405 and 500 and when each one is used. | 20 |
| Safe input handlingAll input validated, id and status set by the server, no internals in errors. | 20 |
| Clean codeA routing table instead of a long if chain; small, named functions. | 15 |
0/5 steps done
Step 1 of 5
Match a route
matchRoute(pattern, path) returns the path parameters ({ id: '42' } for '/complaints/:id' and '/complaints/42'), {} for an exact match, and null when the path does not fit.
Split both the pattern and the path on / and drop the empty parts. They must have the same number of parts. A pattern part that starts with : matches anything and saves the value under that name; any other part must be equal. Path parameters are always strings: "42", not 42.
Run shows what your code prints. Check runs the step's tests. Ctrl+Enter checks too.