A RESTful API built with Rust using Rocket and SeaORM for managing hotel bookings. This API provides endpoints for managing hotels, rooms, guests, and bookings.
🚀 Framework: Rocket v0.5.1
- Type-safe web framework for Rust
- Built-in JSON support
- Robust request handling and routing
- Zero-cost abstractions
🌊 ORM: SeaORM v1.1.0
- Async & Dynamic
- Database-agnostic design
- Type-safe query building
- Schema management with migrations
- 🏨 Hotel management (CRUD operations)
- 🛏️ Room management with availability tracking
- 👥 Guest management
- 📅 Booking management with status tracking
- 📚 OpenAPI/Swagger documentation
- 🔒 Type-safe database operations with SeaORM
- 🚀 Built with Rust's Rocket framework
- Rust (latest stable version)
- PostgreSQL 13 or higher
- Docker & Docker Compose (optional, for containerized database)
- Clone the repository:
git clone https://github.com/SokhengDin/RUST-API.git
cd RUST-API
-
Setup the database:
Using Docker Compose:
docker-compose up -d
Or use your existing PostgreSQL instance and update the .env
file accordingly.
- Create a
.env
file in the project root:
DB_USER=postgres
DB_PASS=seaorm_123
DB_NAME=seaorm_db
DB_PORT=5432
PORT=8000
- Run the migrations:
export DATABASE_URL="postgres://postgres:seaorm_123@localhost:5432/seaorm_db"
cargo run -p migration
- Start the server:
cargo run
The API will be available at http://localhost:8000/api/v1
Once the server is running, you can access the OpenAPI/Swagger documentation at:
http://localhost:8000/swagger-ui/
GET /api/v1/hotels
- List all hotelsGET /api/v1/hotels/{id}
- Get a specific hotelPOST /api/v1/hotels
- Create a new hotelPUT /api/v1/hotels/{id}
- Update a hotelDELETE /api/v1/hotels/{id}
- Delete a hotel
GET /api/v1/rooms
- List all roomsGET /api/v1/rooms/{id}
- Get a specific roomPOST /api/v1/rooms
- Create a new roomPUT /api/v1/rooms/{id}
- Update a roomDELETE /api/v1/rooms/{id}
- Delete a roomGET /api/v1/hotels/{hotel_id}/rooms
- Get rooms for a specific hotel
GET /api/v1/guests
- List all guestsGET /api/v1/guests/{id}
- Get a specific guestPOST /api/v1/guests
- Create a new guestPUT /api/v1/guests/{id}
- Update a guestDELETE /api/v1/guests/{id}
- Delete a guest
GET /api/v1/bookings
- List all bookingsGET /api/v1/bookings/{id}
- Get a specific bookingPOST /api/v1/bookings
- Create a new bookingPUT /api/v1/bookings/{id}
- Update a bookingDELETE /api/v1/bookings/{id}
- Delete a bookingGET /api/v1/guests/{guest_id}/bookings
- Get bookings for a specific guestGET /api/v1/rooms/{room_id}/bookings
- Get bookings for a specific room
.
├── Cargo.toml
├── docker-compose.yml
└── src
├── config/ # Configuration management
├── models/ # Database models
├── routes/ # API endpoints
├── schemas/ # Request/Response schemas
├── services/ # Business logic
└── main.rs # Application entry point
The application uses PostgreSQL with the following main entities:
hotels
- Hotel informationrooms
- Room details and availabilityguests
- Guest informationbookings
- Booking records with status tracking
cargo build --release
- Rust - The programming language
- Rocket - Web framework
- SeaORM - ORM framework
- PostgreSQL - Database
- Utoipa - OpenAPI documentation