Repaso
Español
Backend & APIsIntermediateAPI-29

Design a REST API for a bookings resource (hotel rooms). What endpoints, codes and concerns?

Answer

  • Resources: GET /rooms?from=&to= (availability), POST /bookings (201 + Location), GET /bookings/{id}, PATCH /bookings/{id} (change dates), POST /bookings/{id}/cancel or DELETE (200/204).
  • Errors: 400/422 validation, 401/403 auth, 404 missing, 409 conflict (room already booked), 429 rate limit.
  • Concurrency: prevent double booking with a DB constraint or a transaction with row lock / version check.
  • Idempotency-Key on POST; cursor pagination on lists; filter and sort parameters.
  • Auth (OAuth/JWT), ownership checks, consistent error format, versioning /v1, OpenAPI docs.

Key terms

Practice this question in Repaso