Hotel booking: no double bookings
A hotel booking API. Guests search for free rooms for a range of dates and create bookings; the server gives each booking its id. A room can't be booked twice for the same night: the database refuses the second booking. Every booking response carries an ETag, and the app sends it back in If-Match when it changes a booking. Successful changes return the updated booking. The hotel doesn't keep cancelled bookings: cancelling deletes the booking, and a successful delete returns no body.
For each request, choose the method, the path and the status code the server returns. Some of these requests fail.
1.Find rooms that are free from 5 to 8 November.
2.Book room 12 for those dates.
3.A second guest tries to book room 12 for the same nights, a second later.
4.Move booking 77 to 6–9 November (the room is free for those nights), sending only the new dates and the current ETag.
5.The guest changes booking 77 again from a tab opened earlier. Staff edited the booking in between, so the app sends an old ETag in If-Match.
6.Cancel booking 77.
7.The app reloads booking 77 after it was cancelled.
- GET /rooms?check_in=…&check_out=… → 200: a filtered read of the rooms collection.
- POST /bookings → 201 Created, with Location: /bookings/{id}.
- POST /bookings → 409 Conflict: the request is valid, but the room is already taken. The database's unique rule decides which booking won.
- PATCH /bookings/{id} → 200: a partial update whose If-Match matches the current version.
- PATCH /bookings/{id} → 412 Precondition Failed: the If-Match ETag is out of date, so the server refuses to overwrite the staff's change.
- DELETE /bookings/{id} → 204 No Content. Cancelled bookings aren't kept, so the booking is removed.
- GET /bookings/{id} → 404 Not Found: the booking no longer exists.
Methods
Paths
Status codes
Tap a slot, then a part. Or drag a part into a slot. Each part can be used many times.