Complete API reference for the Vehicle Rental System with request/response specifications.
Access: Public
Description: Register a new user account
POST /api/v1/auth/signup
{
"name": "John Doe",
"email": "john.doe@example.com",
"password": "securePassword123",
"phone": "01712345678",
"role": "customer"
}{
"success": true,
"message": "User registered successfully",
"data": {
"id": 1,
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "01712345678",
"role": "customer"
}
}Access: Public
Description: Login and receive JWT authentication token
POST /api/v1/auth/signin
{
"email": "john.doe@example.com",
"password": "securePassword123"
}{
"success": true,
"message": "Login successful",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": 1,
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "+1234567890",
"role": "customer"
}
}
}Access: Admin only
Description: Add a new vehicle to the system
POST /api/v1/vehicles
Authorization: Bearer <jwt_token>
{
"vehicle_name": "Toyota Camry 2024",
"type": "car",
"registration_number": "ABC-1234",
"daily_rent_price": 50,
"availability_status": "available"
}{
"success": true,
"message": "Vehicle created successfully",
"data": {
"id": 1,
"vehicle_name": "Toyota Camry 2024",
"type": "car",
"registration_number": "ABC-1234",
"daily_rent_price": 50,
"availability_status": "available"
}
}Access: Public
Description: Retrieve all vehicles in the system
GET /api/v1/vehicles
{
"success": true,
"message": "Vehicles retrieved successfully",
"data": [
{
"id": 1,
"vehicle_name": "Toyota Camry 2024",
"type": "car",
"registration_number": "ABC-1234",
"daily_rent_price": 50,
"availability_status": "available"
},
{
"id": 2,
"vehicle_name": "Honda Civic 2023",
"type": "car",
"registration_number": "XYZ-5678",
"daily_rent_price": 45,
"availability_status": "available"
}
]
}{
"success": true,
"message": "No vehicles found",
"data": []
}Access: Public
Description: Retrieve specific vehicle details
GET /api/v1/vehicles/:vehicleId
Example:
GET /api/v1/vehicles/2
{
"success": true,
"message": "Vehicle retrieved successfully",
"data": {
"id": 2,
"vehicle_name": "Honda Civic 2023",
"type": "car",
"registration_number": "XYZ-5678",
"daily_rent_price": 45,
"availability_status": "available"
}
}Access: Admin only
Description: Update vehicle details, price, or availability status
PUT /api/v1/vehicles/:vehicleId
Example:
PUT /api/v1/vehicles/1
Authorization: Bearer <jwt_token>
{
"vehicle_name": "Toyota Camry 2024 Premium",
"type": "car",
"registration_number": "ABC-1234",
"daily_rent_price": 55,
"availability_status": "available"
}{
"success": true,
"message": "Vehicle updated successfully",
"data": {
"id": 1,
"vehicle_name": "Toyota Camry 2024 Premium",
"type": "car",
"registration_number": "ABC-1234",
"daily_rent_price": 55,
"availability_status": "available"
}
}Access: Admin only
Description: Delete a vehicle (only if no active bookings exist)
DELETE /api/v1/vehicles/:vehicleId
Example:
DELETE /api/v1/vehicles/1
Authorization: Bearer <jwt_token>
{
"success": true,
"message": "Vehicle deleted successfully"
}Access: Admin only
Description: Retrieve all users in the system
GET /api/v1/users
Authorization: Bearer <jwt_token>
{
"success": true,
"message": "Users retrieved successfully",
"data": [
{
"id": 1,
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "+1234567890",
"role": "customer"
},
{
"id": 2,
"name": "Admin User",
"email": "admin@example.com",
"phone": "+0987654321",
"role": "admin"
}
]
}Access: Admin or Own Profile
Description: Admin can update any user's role or details. Customer can update own profile only
PUT /api/v1/users/:userId
Example:
PUT /api/v1/users/1
Authorization: Bearer <jwt_token>
{
"name": "John Doe Updated",
"email": "john.updated@example.com",
"phone": "+1234567899",
"role": "admin"
}{
"success": true,
"message": "User updated successfully",
"data": {
"id": 1,
"name": "John Doe Updated",
"email": "john.updated@example.com",
"phone": "+1234567899",
"role": "customer"
}
}Access: Admin only
Description: Delete a user (only if no active bookings exist)
DELETE /api/v1/users/:userId
Example:
DELETE /api/v1/users/1
Authorization: Bearer <jwt_token>
{
"success": true,
"message": "User deleted successfully"
}Access: Customer or Admin
Description: Create a new booking with automatic price calculation and vehicle status update
POST /api/v1/bookings
Authorization: Bearer <jwt_token>
{
"customer_id": 1,
"vehicle_id": 2,
"rent_start_date": "2024-01-15",
"rent_end_date": "2024-01-20"
}{
"success": true,
"message": "Booking created successfully",
"data": {
"id": 1,
"customer_id": 1,
"vehicle_id": 2,
"rent_start_date": "2024-01-15",
"rent_end_date": "2024-01-20",
"total_price": 250,
"status": "active",
"vehicle": {
"vehicle_name": "Honda Civic 2023",
"daily_rent_price": 45
}
}
}Access: Role-based (Admin sees all, Customer sees own)
Description: Retrieve bookings based on user role
GET /api/v1/bookings
Authorization: Bearer <jwt_token>
{
"success": true,
"message": "Bookings retrieved successfully",
"data": [
{
"id": 1,
"customer_id": 1,
"vehicle_id": 2,
"rent_start_date": "2024-01-15",
"rent_end_date": "2024-01-20",
"total_price": 250,
"status": "active",
"customer": {
"name": "John Doe",
"email": "john.doe@example.com"
},
"vehicle": {
"vehicle_name": "Honda Civic 2023",
"registration_number": "XYZ-5678"
}
}
]
}{
"success": true,
"message": "Your bookings retrieved successfully",
"data": [
{
"id": 1,
"vehicle_id": 2,
"rent_start_date": "2024-01-15",
"rent_end_date": "2024-01-20",
"total_price": 250,
"status": "active",
"vehicle": {
"vehicle_name": "Honda Civic 2023",
"registration_number": "XYZ-5678",
"type": "car"
}
}
]
}Access: Role-based
Description: Update booking status based on user role and business rules
PUT /api/v1/bookings/:bookingId
Example:
PUT /api/v1/bookings/1
Authorization: Bearer <jwt_token>
{
"status": "cancelled"
}{
"status": "returned"
}{
"success": true,
"message": "Booking cancelled successfully",
"data": {
"id": 1,
"customer_id": 1,
"vehicle_id": 2,
"rent_start_date": "2024-01-15",
"rent_end_date": "2024-01-20",
"total_price": 250,
"status": "cancelled"
}
}{
"success": true,
"message": "Booking marked as returned. Vehicle is now available",
"data": {
"id": 1,
"customer_id": 1,
"vehicle_id": 2,
"rent_start_date": "2024-01-15",
"rent_end_date": "2024-01-20",
"total_price": 250,
"status": "returned",
"vehicle": {
"availability_status": "available"
}
}
}{
"success": true,
"message": "Operation description",
"data": "Response data"
}{
"success": false,
"message": "Error description",
"errors": "Error description"
}| Code | Meaning | Usage |
|---|---|---|
| 200 | OK | Successful GET, PUT, DELETE |
| 201 | Created | Successful POST (resource created) |
| 400 | Bad Request | Validation errors, invalid input |
| 401 | Unauthorized | Missing or invalid authentication token |
| 403 | Forbidden | Valid token but insufficient permissions |
| 404 | Not Found | Resource doesn't exist |
| 500 | Internal Server Error | Unexpected server errors |
All protected endpoints require the following header:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
total_price = daily_rent_price × number_of_days
number_of_days = rent_end_date - rent_start_date
- When booking is created → Vehicle status changes to
"booked" - When booking is marked as
"returned"→ Vehicle status changes to"available" - When booking is
"cancelled"→ Vehicle status changes to"available"
- System automatically marks bookings as
"returned"whenrent_end_datehas passed - Vehicle availability status is updated accordingly
- Users cannot be deleted if they have active bookings
- Vehicles cannot be deleted if they have active bookings
- Active bookings = bookings with status
"active"