This is a Node.js + Express based Meeting Room Booking API that allows users to:
- View available meeting rooms
- Retrieve bookings for a specific room
- Create new bookings with conflict validation
- Update existing bookings
- Delete bookings
- Handle concurrent booking attempts
Ensure you have Node.js and npm installed on your system.
cd meeting-room-booking-apinpm installnode index.jsThe server will start at http://localhost:3000
Endpoint: GET /rooms
Description: Returns a list of all available meeting rooms.
Response:
[
{ "id": "room-1", "name": "Conference Room A" },
{ "id": "room-2", "name": "Conference Room B" }
]Endpoint: GET /rooms/:roomId/bookings
Description: Retrieves all bookings for a specified room.
Response:
[
{ "id": "booking-1", "userId": "user-123", "startTime": "2025-03-01T10:00:00Z", "endTime": "2025-03-01T11:00:00Z" }
]Endpoint: POST /rooms/:roomId/bookings
Request Body:
{
"userId": "user-123",
"startTime": "2025-03-01T10:00:00Z",
"endTime": "2025-03-01T11:00:00Z"
}Validation Checks:
- Start time and end time must be valid ISO 8601 strings.
- Start time must be before end time.
- The booking must not conflict with existing bookings.
- A locking mechanism prevents concurrent booking conflicts.
Response:
{
"id": "generated-uuid",
"userId": "user-123",
"startTime": "2025-03-01T10:00:00Z",
"endTime": "2025-03-01T11:00:00Z"
}Endpoint: PUT /rooms/:roomId/bookings/:bookingId
Request Body:
{
"startTime": "2025-03-01T12:00:00Z",
"endTime": "2025-03-01T13:00:00Z"
}Response:
{
"id": "booking-1",
"userId": "user-123",
"startTime": "2025-03-01T12:00:00Z",
"endTime": "2025-03-01T13:00:00Z"
}Endpoint: DELETE /rooms/:roomId/bookings/:bookingId
Response:
{
"message": "Booking deleted successfully."
}-
In-memory Data Storage:
- Instead of a database, we use JavaScript objects to store rooms and bookings.
-
Conflict Prevention:
- Before confirming a booking, we check for overlapping time slots.
-
Concurrent Booking Handling:
- A locking mechanism prevents simultaneous bookings from conflicting.
-
Error Handling:
- Proper validation and HTTP status codes (
400,404,409) are implemented.
- Proper validation and HTTP status codes (
Below is the explaination on how to test each API endpoint in detail using Postman.
- Ensure the API is running by executing:
The server should start at
node index.js
http://localhost:3000.
Endpoint: GET /rooms
- Open Postman.
- Select GET request.
- Enter the URL:
http://localhost:3000/rooms - Click Send.
[
{ "id": "room-1", "name": "Conference Room A" },
{ "id": "room-2", "name": "Conference Room B" }
]Endpoint: GET /rooms/:roomId/bookings
- Select GET request.
- Enter URL:
http://localhost:3000/rooms/room-1/bookings - Click Send.
[
{ "id": "booking-1", "userId": "user-123", "startTime": "2025-03-01T10:00:00Z", "endTime": "2025-03-01T11:00:00Z" }
]Endpoint: POST /rooms/:roomId/bookings
- Select POST request.
- Enter URL:
http://localhost:3000/rooms/room-1/bookings - Go to Body > raw > JSON and enter:
{
"userId": "user-123",
"startTime": "2025-03-01T10:00:00Z",
"endTime": "2025-03-01T11:00:00Z"
}- Click Send.
{
"id": "generated-uuid",
"userId": "user-123",
"startTime": "2025-03-01T10:00:00Z",
"endTime": "2025-03-01T11:00:00Z"
}Endpoint: PUT /rooms/:roomId/bookings/:bookingId
- Select PUT request.
- Enter URL:
http://localhost:3000/rooms/room-1/bookings/booking-1 - Go to Body > raw > JSON and enter:
{
"startTime": "2025-03-01T12:00:00Z",
"endTime": "2025-03-01T13:00:00Z"
}- Click Send.
{
"id": "booking-1",
"userId": "user-123",
"startTime": "2025-03-01T12:00:00Z",
"endTime": "2025-03-01T13:00:00Z"
}Endpoint: DELETE /rooms/:roomId/bookings/:bookingId
- Select DELETE request.
- Enter URL:
http://localhost:3000/rooms/room-1/bookings/booking-1 - Click Send.
{
"message": "Booking deleted successfully."
}-
Invalid Room ID
- Try accessing a non-existent room's bookings:
GET /rooms/non-existent-room/bookings - Expected:
{ "error": "Room not found." }
- Try accessing a non-existent room's bookings:
-
Booking with overlapping times
- Try creating two bookings with the same time slot and check for
409 Conflicterror.
- Try creating two bookings with the same time slot and check for
-
Concurrent Booking Handling
- Simulate multiple users booking the same time slot using Postman runner.