This guide demonstrates how to test the new POST response format that includes request body in responses.
-
Start the backend server:
cd backend npm install npm start -
Server should be running on:
http://localhost:5000
This endpoint always works, even without database:
curl http://localhost:5000/Expected Response:
{
"message": "EcoRide Backend API",
"version": "1.0.0",
"endpoints": {
"health": "/health",
"auth": "/api/auth",
"documents": "/api/documents",
...
}
}curl http://localhost:5000/healthExpected Response (without database):
{
"status": "ERROR",
"message": "Database connection failed",
"error": ""
}Expected Response (with database):
{
"status": "OK",
"timestamp": "2024-02-09T19:30:00.000Z",
"uptime": 123.45,
"database": "Connected"
}curl -X POST http://localhost:5000/api/auth/signup \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"password": "password123",
"role": "Rider"
}'Expected Response (NEW FORMAT with requestBody):
{
"success": true,
"message": "User registered successfully",
"requestBody": {
"name": "John Doe",
"email": "john@example.com",
"password": "[FILTERED]",
"role": "Rider"
},
"data": {
"user": {
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"role": "Rider",
"status": "Active",
"verified": false,
"profile_setup_complete": false,
"rating": 0,
"total_rides": 0,
"created_at": "2024-02-09T19:30:00.000Z"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}- ✅ requestBody is included showing what you sent
- ✅ password is automatically filtered as
[FILTERED] - ✅ data contains the created user and auth token
curl -X POST http://localhost:5000/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "password123"
}'Expected Response (NEW FORMAT):
{
"success": true,
"message": "Login successful",
"requestBody": {
"email": "john@example.com",
"password": "[FILTERED]"
},
"data": {
"user": {
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"role": "Rider",
...
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}First, get your token from the login response, then:
curl -X POST http://localhost:5000/api/rides \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-d '{
"rider_id": 1,
"driver_id": 2,
"pickup_location": "123 Main St, New York, NY",
"dropoff_location": "456 Park Ave, New York, NY",
"pickup_lat": 40.7128,
"pickup_lng": -74.0060,
"dropoff_lat": 40.7589,
"dropoff_lng": -73.9851,
"ride_type": "solo",
"fare": 25.50,
"distance": 5.2
}'Expected Response (NEW FORMAT):
{
"success": true,
"message": "Ride created successfully and driver notified",
"requestBody": {
"rider_id": 1,
"driver_id": 2,
"pickup_location": "123 Main St, New York, NY",
"dropoff_location": "456 Park Ave, New York, NY",
"pickup_lat": 40.7128,
"pickup_lng": -74.006,
"dropoff_lat": 40.7589,
"dropoff_lng": -73.9851,
"ride_type": "solo",
"fare": 25.5,
"distance": 5.2
},
"data": {
"id": 1,
"rider_id": 1,
"driver_id": 2,
"pickup_location": "123 Main St, New York, NY",
"dropoff_location": "456 Park Ave, New York, NY",
"status": "Pending",
"fare": 25.5,
"distance": 5.2,
"ride_type": "solo",
"created_at": "2024-02-09T19:35:00.000Z"
}
}- ✅ requestBody shows exactly what you sent
- ✅ data shows the created ride with server-added fields (id, status, created_at)
- ✅ Compare input vs output easily!
curl -X POST http://localhost:5000/api/auth/upload-photo \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-F "photo=@/path/to/photo.jpg"Expected Response (NEW FORMAT with meta):
{
"success": true,
"message": "Profile photo uploaded successfully",
"requestBody": {},
"data": {
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"profile_photo": "/uploads/profile-photos/profile-1707509400000-123456789.jpg",
...
},
"meta": {
"filename": "profile-1707509400000-123456789.jpg",
"size": 245678,
"mimetype": "image/jpeg"
}
}- ✅ meta includes file upload details
- ✅ Useful for debugging file uploads
Try signup with an existing email:
curl -X POST http://localhost:5000/api/auth/signup \
-H "Content-Type: application/json" \
-d '{
"name": "Jane Doe",
"email": "john@example.com",
"password": "password456",
"role": "Rider"
}'Expected Response (Error with requestBody):
{
"success": false,
"message": "Email already registered",
"requestBody": {
"name": "Jane Doe",
"email": "john@example.com",
"password": "[FILTERED]",
"role": "Rider"
}
}- ✅ Even errors include requestBody
- ✅ Helps debugging by seeing what was sent
- ✅ Password still filtered for security
{
"success": true,
"message": "User registered successfully",
"data": {
"user": { ... },
"token": "..."
}
}{
"success": true,
"message": "User registered successfully",
"requestBody": {
"name": "John Doe",
"email": "john@example.com",
"password": "[FILTERED]",
"role": "Rider"
},
"data": {
"user": { ... },
"token": "..."
}
}- 🐛 Better Debugging: See exactly what was sent vs what was received
- 📚 Educational: Learn how the API processes your data
- 🔍 Transparency: Understand data flow clearly
- 🔒 Secure: Sensitive fields automatically filtered
- ✅ Consistent: All POST endpoints follow same pattern
✅ 21 POST endpoints now use this format:
- Authentication (8 endpoints)
- Rides (1 endpoint)
- Chat (2 endpoints)
- Emergency (1 endpoint)
- Notifications (2 endpoints)
- Reports (1 endpoint)
- Settings (2 endpoints)
- Documents (2 endpoints)
- Users (1 endpoint)
GET endpoints work as before - no changes:
curl http://localhost:5000/api/rides
curl http://localhost:5000/api/users
curl http://localhost:5000/api/emergencyIf GET/POST endpoints return database errors, set up PostgreSQL:
# Install PostgreSQL
sudo apt-get install postgresql postgresql-contrib
# Start service
sudo service postgresql start
# Create database
sudo -u postgres createdb ecoride_db
# Initialize schema
cd backend
npm run init-db
# Restart server
npm startImport the Postman collection (postman_collection.json) to test all endpoints easily with pre-configured requests!
Happy Testing! 🚀