The Driving School Management System API is a RESTful service built with Node.js, Express.js, and MySQL/PostgreSQL. It provides comprehensive functionality for managing driving school operations including user authentication, booking management, payment processing, and administrative features.
- Development:
http://localhost:5001 - Production:
https://your-domain.com
The API uses JWT (JSON Web Tokens) for authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
- Access Token: Short-lived token (15 minutes) for API requests
- Refresh Token: Long-lived token (7 days) for obtaining new access tokens
All API responses follow a consistent format:
{
"success": true,
"data": {
// Response data
},
"message": "Operation completed successfully"
}{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Human readable error message",
"details": "Additional error details"
}
}200- Success201- Created400- Bad Request401- Unauthorized403- Forbidden404- Not Found409- Conflict422- Validation Error429- Too Many Requests500- Internal Server Error
- Limit: 100 requests per 15 minutes per IP
- Headers:
X-RateLimit-Limit: Request limitX-RateLimit-Remaining: Remaining requestsX-RateLimit-Reset: Reset time (Unix timestamp)
POST /api/auth/registerRequest Body:
{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"password": "SecurePass123!",
"confirmPassword": "SecurePass123!",
"phone": "+1234567890",
"role": "student"
}Response:
{
"success": true,
"data": {
"user": {
"id": 1,
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"role": "student",
"createdAt": "2024-01-15T10:30:00Z"
},
"tokens": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}
}POST /api/auth/loginRequest Body:
{
"email": "john.doe@example.com",
"password": "SecurePass123!"
}POST /api/auth/refresh-tokenRequest Body:
{
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}GET /api/auth/profile
Authorization: Bearer <access-token>PUT /api/auth/profile
Authorization: Bearer <access-token>Request Body:
{
"firstName": "John",
"lastName": "Doe",
"phone": "+1234567890"
}PUT /api/auth/change-password
Authorization: Bearer <access-token>Request Body:
{
"currentPassword": "OldPass123!",
"newPassword": "NewPass123!",
"confirmPassword": "NewPass123!"
}POST /api/auth/forgot-passwordRequest Body:
{
"email": "john.doe@example.com"
}POST /api/auth/reset-passwordRequest Body:
{
"token": "reset-token-from-email",
"password": "NewPass123!",
"confirmPassword": "NewPass123!"
}GET /api/auth/googleGET /api/auth/google/callbackGET /api/bookings
Authorization: Bearer <access-token>Query Parameters:
page(optional): Page number (default: 1)limit(optional): Items per page (default: 10)status(optional): Filter by status (pending, confirmed, completed, cancelled)
Response:
{
"success": true,
"data": {
"bookings": [
{
"id": 1,
"instructorId": 1,
"packageId": 1,
"date": "2024-01-20",
"time": "10:00",
"duration": 60,
"status": "confirmed",
"notes": "First lesson",
"instructor": {
"id": 1,
"firstName": "Jane",
"lastName": "Smith"
},
"package": {
"id": 1,
"name": "Beginner Package",
"price": 299.99
}
}
],
"pagination": {
"currentPage": 1,
"totalPages": 5,
"totalItems": 50,
"itemsPerPage": 10
}
}
}POST /api/bookings
Authorization: Bearer <access-token>Request Body:
{
"instructorId": 1,
"packageId": 1,
"date": "2024-01-20",
"time": "10:00",
"duration": 60,
"notes": "First lesson"
}PUT /api/bookings/:id
Authorization: Bearer <access-token>DELETE /api/bookings/:id
Authorization: Bearer <access-token>GET /api/instructorsQuery Parameters:
available(optional): Filter by availability (true/false)specialty(optional): Filter by specialty
Response:
{
"success": true,
"data": [
{
"id": 1,
"firstName": "Jane",
"lastName": "Smith",
"email": "jane.smith@drivingschool.com",
"phone": "+1234567890",
"experience": 5,
"specialties": ["Beginner", "Highway"],
"rating": 4.8,
"bio": "Experienced instructor with 5 years of teaching",
"availability": {
"monday": ["09:00", "14:00"],
"tuesday": ["10:00", "15:00"],
"wednesday": ["09:00", "16:00"],
"thursday": ["10:00", "14:00"],
"friday": ["09:00", "15:00"]
}
}
]
}GET /api/instructors/:idGET /api/packagesResponse:
{
"success": true,
"data": [
{
"id": 1,
"name": "Beginner Package",
"description": "Perfect for first-time drivers",
"price": 299.99,
"duration": 10,
"lessons": 10,
"features": [
"10 driving lessons",
"Theory classes",
"Test preparation",
"Certificate of completion"
],
"isActive": true
}
]
}POST /api/payments/create-payment-intent
Authorization: Bearer <access-token>Request Body:
{
"amount": 29999,
"currency": "usd",
"packageId": 1,
"bookingIds": [1, 2, 3]
}Response:
{
"success": true,
"data": {
"clientSecret": "pi_1234567890_secret_abcdef",
"paymentIntentId": "pi_1234567890"
}
}POST /api/payments/confirm-payment
Authorization: Bearer <access-token>Request Body:
{
"paymentIntentId": "pi_1234567890",
"packageId": 1
}GET /api/payments/history
Authorization: Bearer <access-token>Query Parameters:
page(optional): Page numberlimit(optional): Items per page
GET /api/admin/users
Authorization: Bearer <admin-access-token>PUT /api/admin/users/:id
Authorization: Bearer <admin-access-token>GET /api/admin/bookings
Authorization: Bearer <admin-access-token>PUT /api/admin/bookings/:id
Authorization: Bearer <admin-access-token>Request Body:
{
"status": "completed"
}GET /api/admin/payments
Authorization: Bearer <admin-access-token>POST /api/contactRequest Body:
{
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "+1234567890",
"subject": "Inquiry about driving lessons",
"message": "I would like to know more about your beginner package."
}GET /healthResponse:
{
"status": "OK",
"message": "Driving School API is running",
"timestamp": "2024-01-15T10:30:00Z"
}AUTH_001: Invalid credentialsAUTH_002: Token expiredAUTH_003: Token invalidAUTH_004: Insufficient permissionsAUTH_005: Account not verified
VAL_001: Required field missingVAL_002: Invalid email formatVAL_003: Password too weakVAL_004: Invalid phone numberVAL_005: Date in the past
BIZ_001: Instructor not availableBIZ_002: Booking time conflictBIZ_003: Package not foundBIZ_004: Payment failedBIZ_005: Insufficient balance
SYS_001: Database connection errorSYS_002: External service unavailableSYS_003: File upload failedSYS_004: Email service error
The API accepts Stripe webhooks for payment events:
POST /api/webhooks/stripeSupported Events:
payment_intent.succeededpayment_intent.payment_failedinvoice.payment_succeededinvoice.payment_failed
npm install axiosimport axios from 'axios';
const api = axios.create({
baseURL: 'http://localhost:5001/api',
headers: {
'Content-Type': 'application/json'
}
});
// Add token to requests
api.interceptors.request.use((config) => {
const token = localStorage.getItem('accessToken');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});pip install requestsimport requests
class DrivingSchoolAPI:
def __init__(self, base_url, token=None):
self.base_url = base_url
self.session = requests.Session()
if token:
self.session.headers.update({
'Authorization': f'Bearer {token}'
})
def get_bookings(self):
response = self.session.get(f'{self.base_url}/api/bookings')
return response.json()Use the test environment for development and testing:
- Base URL:
http://localhost:5001 - Test Cards: See Stripe test cards below
- Admin:
admin@drivingschool.com/Admin123! - Instructor:
instructor@drivingschool.com/Instructor123! - Student: Register new account
- Success:
4242 4242 4242 4242 - Decline:
4000 0000 0000 0002 - Insufficient Funds:
4000 0000 0000 9995 - Expiry:
12/25 - CVC:
123
| Endpoint Type | Limit | Window |
|---|---|---|
| Authentication | 10 requests | 15 minutes |
| General API | 100 requests | 15 minutes |
| File Upload | 20 requests | 1 hour |
| Payment | 50 requests | 1 hour |
All production endpoints require HTTPS. Development endpoints use HTTP.
Cross-Origin Resource Sharing is configured for specific domains:
- Development:
http://localhost:3000 - Production: Your production domain
Security headers are automatically added:
X-Content-Type-Options: nosniffX-Frame-Options: DENYX-XSS-Protection: 1; mode=blockStrict-Transport-Security: max-age=31536000
For API support and questions:
- Documentation: This file
- Issues: GitHub Issues
- Email: api-support@drivingschool.com
- Initial API release
- Authentication system
- Booking management
- Payment processing
- Admin dashboard
- Contact form