“Bonz.ai, the company behind the hotel, has always strived to be at the forefront when it comes to using technology to enhance the customer experience. They have a strong culture of innovation and are not afraid to think outside the box.
You have been hired to build their booking API, and for this project, a serverless architecture in AWS was chosen. This means you don’t need to worry about managing or maintaining servers. Instead, you can focus on building and improving your application. Additionally, the serverless architecture allows Bonz.ai to scale up or down based on demand, which is perfect for their booking system that may experience varying traffic at different times of the day or year. ☁️
To store all booking information, DynamoDB was chosen, a NoSQL database offered by AWS. DynamoDB is an excellent choice for their booking API because it offers fast and predictable performance, as well as automatic scaling.”
- Serverless framework
- API Gateway
- AWS Lambda
- DynamoDB
| Method | Endpoint | Description |
|---|---|---|
| GET | /bookings | Overview of the bookings for receptionist |
| POST | /bookings | Make a hotel reservation |
| PUT | /bookings/:id | Make changes to a reservation |
| DELETE | /bookings/:id | Delete a reservation |
Follow these steps to create a local copy and run the project:
- Clone the repository:
git clone https://github.com/trojandersen/bonzai.git
- Navigate to the project directory:
cd bonzai - Install dependencies:
npm install
- Change the yml-file so that it connects to your AWS development service:
org: *name-of-your-org*
- In order to deploy the project you need to open the terminal and enter the following command:
sls deploy
- After deployment you should se similar:
endpoints:
GET - https://xxxxxxxxxxxxx.execute-api.eu-north-1.amazonaws.com/bookings
POST - https://xxxxxxxxxxxxx.execute-api.eu-north-1.amazonaws.com/bookings
PUT - https://xxxxxxxxxxxxx.execute-api.eu-north-1.amazonaws.com/bookings/{id}
DELETE - https://xxxxxxxxxxxxx.execute-api.eu-north-1.amazonaws.com/bookings/{id}
functions:
getBooking: bonzai-dev-getBooking (10 kB)
postBooking: bonzai-dev-postBooking (10 kB)
putId: bonzai-dev-putId (10 kB)
deleteId: bonzai-dev-deleteId (10 kB)
Common errors and their handling mechanisms are as follows:
- 400 Bad Request: Invalid input format or missing parameters.
- 404 Not Found: Requested resource does not exist.
- 500 Internal Server Error: General server error.
GET /bookingsResponse:
{
"data": {
"bookings": [
{
"bookingId": "64352643",
"checkIn": "2024-09-13",
"checkOut": "2024-09-17",
"guests": 1,
"name": "Paloma Wool",
"numOfSingleRooms": 1
},
{
"bookingId": "98745678",
"checkIn": "2024-09-13",
"checkOut": "2024-09-15",
"guests": 4,
"name": "Gwen Stefanie",
"numOfDoubleRooms": 2
}
]
}
}POST /bookingsRequest syntax:
{
"name": "Jose Gonzalez",
"email": "jg@gmail.com",
"guests": 1,
"numOfSingleRooms": 1,
"numOfDoubleRooms": 0,
"numOfSuiteRooms": 0,
"checkIn": "2024-09-13",
"checkOut": "2024-09-16"
}Response:
{
"bookingId": 876875,
"name": "Jose Gonzalez",
"guests": 1,
"numOfSingleRooms": 1,
"numOfDoubleRooms": 0,
"numOfSuiteRooms": 0,
"checkIn": "2024-09-13",
"checkOut": "2024-09-16",
"totalPrice": 1500
}400 Bad request - Too many guests per room:
{
"errorMessage": "Number of guests exceeds the available number of beds."
}400 Bad request - Missing fields:
{
"errorMessage": "Missing required fields in the request body."
}500 Bad request - Insufficient rooms:
{
"errorMessage": "Not enough available Suite rooms."
}Instructions: Here you need the bookingIdand use it in the parapath parameter:
PUT /bookings/:idRequest syntax:
{
"guests": 1,
"numOfSingleRooms": 1,
"numOfDoubleRooms": 0,
"numOfSuiteRooms": 0,
"checkIn": "2024-09-13", //date cannot be after check-in
"checkOut": "2024-09-19"
}Response if changes were successful:
{
"data": {
"message": "Booking updated successfully.",
"updatedAttributes": {
"checkIn": "2024-09-13",
"numOfDoubleRooms": 0,
"totalPrice": 1000,
"guests": 1,
"checkOut": "2024-09-15",
"numOfSingleRooms": 1,
"rooms": [
"101"
],
"numOfSuiteRooms": 0
}
}
}404 Not found - If bookingId does not exists in bookings table:
{
"errorMessage": "Booking not found."
}400 Bad request - Too many guests per room:
{
"errorMessage": "Number of guests exceeds the available number of beds."
}400 Bad request - Missing fields:
{
"errorMessage": "Missing required fields in the request body."
}500 Bad request - Insufficient rooms:
{
"errorMessage": "Not enough available Suite rooms."
}Instructions: Here you need the bookingIdand use it in the parapath parameter:
DELETE /bookings/:idResponse if something is in cart:
{
"message": "Booking successfully deleted!"
}400 Bad request - If todays date is less than two days before check-in
{
"errorMessage": {
"message": "Booking can only be cancelled up to 2 days before check-in date"
}
}404 Bad request - If bookingId is incorrect
{
"errorMessage": {
"message": "Booking not found"
}
}