Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/leuthra/booking-api

Booking API is a lightweight RESTful API built with hono, mysql and powered by Bun
https://github.com/leuthra/booking-api

booking-system bun hono restful-api

Last synced: 3 days ago
JSON representation

Booking API is a lightweight RESTful API built with hono, mysql and powered by Bun

Awesome Lists containing this project

README

        

# Booking API

The **Booking API** is a lightweight RESTful API built with **Hono**, **MySQL**, **TypeScript**, and powered by **Bun**. This API allows you to manage bookings, including creating, reading, updating, and deleting reservations.

## Author
- **Romi Muharom**

---

## Features
1. **Create a new booking**
2. **View all bookings**
3. **View booking details by ID**
4. **Update an existing booking**
5. **Delete a booking**

---

## ๐Ÿ› ๏ธ Technology Stack
- [Bun](https://bun.sh/) - A fast JavaScript runtime
- [Hono](https://hono.dev/) - Lightweight web framework for building APIs
- [TypeScript](https://www.typescriptlang.org/) - A superset of JavaScript with static typing
- [MySQL](https://www.mysql.com/) - Relational database management system
- [dotenv](https://www.npmjs.com/package/dotenv) - For managing environment variables

---

## ๐Ÿ“‚ Project Structure
```bash
booking-api/
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ index.ts # Main server file
โ”‚ โ”œโ”€โ”€ db.ts # MySQL database connection
โ”‚ โ”œโ”€โ”€ migrate.ts # Database migration script
โ”‚ โ”œโ”€โ”€ routes/
โ”‚ โ”‚ โ””โ”€โ”€ bookings.ts # API routes for bookings
โ”‚ โ”œโ”€โ”€ types.ts # TypeScript type definitions
โ”œโ”€โ”€ .env # Environment variables configuration
โ”œโ”€โ”€ .gitignore # Ignore files for Git
โ”œโ”€โ”€ package.json # Bun project configuration
โ”œโ”€โ”€ tsconfig.json # TypeScript configuration
โ”œโ”€โ”€ README.md # Documentation
```

---

## ๐Ÿ”ง Installation and Usage

### 1. **Clone the Project**
```bash
git clone https://github.com/leuthra/booking-api.git
cd booking-api
```

### 2. **Install Dependencies**
```bash
bun install
```

### 3. **Create a `.env` File**
Add your MySQL database configuration in the `.env` file:
```
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=booking_db
DB_PORT=3306
```

### 4. **Run Database Migration**
To create the necessary tables and insert dummy data, run the migration script:
```bash
bun run src/migrate.ts
```

This will create the **bookings** table and populate it with some dummy data.

---

## ๐Ÿš€ API Endpoints

### **Base URL**
```
http://localhost:3000/api
```

### **1. GET `/api/bookings`**
Retrieve all bookings.

#### Example Response
```json
{
"author": "Romi Muharom",
"status": 200,
"message": "List of bookings",
"data": [
{
"id": 1,
"name": "John Doe",
"phone": "08123456789",
"date": "2025-02-01",
"time": "18:00:00",
"people": 2
}
]
}
```

---

### **2. POST `/api/bookings`**
Create a new booking.

#### Request Body
```json
{
"name": "Romi",
"phone": "08123456789",
"date": "2025-02-01",
"time": "18:00:00",
"people": 2
}
```

#### Example Response
```json
{
"author": "Romi Muharom",
"status": 201,
"message": "Booking created",
"id": 1,
"name": "Romi",
"phone": "08123456789",
"date": "2025-02-01",
"time": "18:00:00",
"people": 2
}
```

---

### **3. GET `/api/bookings/:id`**
Retrieve booking details by ID.

#### Example Response
```json
{
"author": "Romi Muharom",
"status": 200,
"message": "Booking detail",
"data": {
"id": 1,
"name": "John Doe",
"phone": "08123456789",
"date": "2025-02-01",
"time": "18:00:00",
"people": 2
}
}
```

---

### **4. PUT `/api/bookings/:id`**
Update a booking by ID.

#### Request Body
```json
{
"name": "Updated Name",
"phone": "08198765432",
"date": "2025-02-02",
"time": "19:00:00",
"people": 4
}
```

#### Example Response
```json
{
"author": "Romi Muharom",
"status": 200,
"message": "Booking updated",
"id": 1,
"name": "Updated Name",
"phone": "08198765432",
"date": "2025-02-02",
"time": "19:00:00",
"people": 4
}
```

---

### **5. DELETE `/api/bookings/:id`**
Delete a booking by ID.

#### Example Response
```json
{
"author": "Romi Muharom",
"status": 200,
"message": "Booking deleted",
"id": 1
}
```

---

## ๐Ÿงช Testing
You can test the API using [Postman](https://www.postman.com/) or any API testing tool of your choice.

---

## ๐Ÿ“œ License
This project is licensed under the [MIT License](LICENSE).

---

If you have any questions or encounter any issues, feel free to reach out! ๐Ÿ˜Š