Skip to content

Project · Backend Development

Project: a bus booking API

Projectbeginner· about 5 hours· 6 steps

The brief

Night Rider runs overnight buses from Pune and Mumbai to Goa and Hyderabad. Build its booking API: a routing table, trip search with query parameters, bookings with validation and seat checks, booking lookup, cancellation with refund rules, and one entry point that never crashes.

Why it matters

Bus, train, movie and doctor-appointment apps all share this backend: search, book, look up, cancel. The tricky parts are the same everywhere: validate every field, never sell more seats than exist (409), apply time-based refund rules, and send errors in one consistent JSON shape that the app can rely on.

Skills you practise

  • REST endpoints and a routing table
  • query and path parameters
  • validation and 400 errors
  • 404 and 409 status codes
  • dates and time zones (IST)
  • consistent JSON errors
  • error handling

What you will have at the end

api.js: a complete, tested booking API (search, book, look up, cancel) with consistent errors, ready to put behind Express.

How it is marked (rubric, 100 points)
Correct behaviourEvery check passes, including full buses, double cancels and the refund boundaries.40
Right status codes and errors200, 201, 400, 404, 405, 409 and 500 used correctly, always in the { error: { code, message } } shape.25
Trusts nothing from the clientEvery field validated; amount, id and status set by the server.20
Clean codeA routing table, small handlers, no repeated code.15

0/6 steps done

Step 1 of 6

The routing table

route(method, path) returns { handler, params } for GET /trips, POST /bookings, GET /bookings/:id and DELETE /bookings/:id; { status: 404 } for an unknown path; { status: 405, allow } for a known path with the wrong method.

Write the API's four endpoints as data: [method, pattern, handler name]. route() first finds every row whose pattern fits the path, then the one with the right method. If the path fits but the method does not, the client needs 405 and the list of allowed methods, not 404, so it knows the address is right.

Run shows what your code prints. Check runs the step's tests. Ctrl+Enter checks too.