Booking API Documentation
A RESTful API built with Yii Basic template for managing bookings across multiple websites. This API allows registered websites to perform CRUD operations on bookings while preventing time slot overlaps.
Features
- Website registration and authentication
- Booking management (CRUD operations)
- Automatic time slot validation
- RESTful architecture
- Pagination support
- Website-specific statistics
Authentication
All API endpoints require Bearer token authentication. To obtain a token:
- Register your website using the registration endpoint
- Include the received token in subsequent requests using the
Authorization: Bearer <token>header
API Endpoints
Website Registration
POST https://bookings.bekhruzbek.uz/v1/websites/register{
"name": "Your Website Name",
"email": "contact@yourwebsite.com"
}
Create Booking
POST https://bookings.bekhruzbek.uz/v1/bookings{
"service_name": "Premium Service",
"customer_name": "John Doe",
"customer_contact": "998908887766",
"booking_date": "2024-10-30",
"start_time": "12:00",
"end_time": "12:30",
"duration_minutes": "30"
}
Website Statistics
GET https://bookings.bekhruzbek.uz/v1/bookings/statisticsResponse format:
{
"status": "success",
"data": {
"totalBookings": {
"count": 3,
"percentage": 100
},
"mostSellingTime": {
"hour": 14,
"count": 2,
"percentage": 66.67
},
"mostSellingDay": {
"day": "Wednesday",
"count": 1,
"percentage": 33.33
},
"mostSellingDuration": {
"durationMinutes": 30,
"count": 3,
"percentage": 100
},
"mostSellingService": {
"serviceName": "Premium Service",
"count": 2,
"percentage": 66.67
},
"returnClients": {
"count": 1,
"details": [
{
"customerContact": "998908887766",
"customerName": "John Doe",
"bookings": 3
}
]
}
}
}
Other Endpoints
| Endpoint | Method | Description |
|---|---|---|
/v1/bookings/{id} |
GET | Get single booking |
/v1/bookings/{id} |
PUT | Update booking |
/v1/bookings/{id} |
DELETE | Delete booking |
Business Rules
-
Time slot validation:
- Each time slot can only be booked once per day per website
- No overlapping bookings are allowed for the same website on the same day
-
Authentication:
- All endpoints except website registration require valid Bearer token
- Website ID is automatically assigned based on authentication token
Installation
-
Create a new Yii Basic project:
composer create-project --prefer-dist yiisoft/yii2-app-basic booking-api
-
Add the repository as remote and pull:
git remote add origin https://github.com/bekhruzcodes/bookings.git git pull origin main
-
Configure the following files according to your environment:
config/db.phpconfig/web.phpconfig/console.phpconfig/params.php
-
Run migrations:
php yii migrate