POST /users/register
This endpoint allows a new user to register by providing their first name, last name, email, and password. The password will be hashed before storing in the database.
The request body should be a JSON object with the following properties:
fullname
: An object containing:firstname
: A string representing the user's first name (minimum 3 characters).lastname
: A string representing the user's last name (minimum 3 characters).
email
: A string representing the user's email (must be a valid email format).password
: A string representing the user's password (minimum 5 characters).
Example:
{
"fullname": {
"firstname": "John",
"lastname": "Doe"
},
"email": "[email protected]",
"password": "password123"
}
- Status Code:
201 Created
- Body: A JSON object containing the authentication token and user details.
{ "token": "jwt_token_here", "user": { "_id": "user_id_here", "fullname": { "firstname": "John", "lastname": "Doe" }, "email": "[email protected]", "socketId": null } }
- Status Code:
400 Bad Request
- Body: A JSON object containing an array of validation error messages.
{ "errors": [ { "msg": "Invalid email", "param": "email", "location": "body" }, { "msg": "Name must be at least 3 characters long", "param": "fullname.firstname", "location": "body" }, { "msg": "Password must be at least 5 characters long", "param": "password", "location": "body" } ] }
- Status Code:
400 Bad Request
- Body: A JSON object containing an error message.
{ "message": "All fields are required" }
- Ensure that the
Content-Type
header is set toapplication/json
when making the request. - The password is hashed before being stored in the database for security purposes.
POST /users/login
This endpoint allows an existing user to log in by providing their email and password.
The request body should be a JSON object with the following properties:
email
: A string representing the user's email (must be a valid email format).password
: A string representing the user's password (minimum 5 characters).
Example:
{
"email": "[email protected]",
"password": "password123"
}
- Status Code:
200 OK
- Body: A JSON object containing the authentication token and user details.
{ "token": "jwt_token_here", "user": { "_id": "user_id_here", "fullname": { "firstname": "John", "lastname": "Doe" }, "email": "[email protected]", "socketId": null } }
- Status Code:
400 Bad Request
- Body: A JSON object containing an array of validation error messages.
{ "errors": [ { "msg": "Invalid email", "param": "email", "location": "body" }, { "msg": "Password must be at least 5 characters long", "param": "password", "location": "body" } ] }
- Status Code:
401 Unauthorized
- Body: A JSON object containing an error message.
{ "message": "Invalid email or password" }
- Ensure that the
Content-Type
header is set toapplication/json
when making the request.
GET /users/profile
This endpoint allows an authenticated user to retrieve their profile information.
Authorization
: A string containing the Bearer token.
Example:
Authorization: Bearer jwt_token_here
- Status Code:
200 OK
- Body: A JSON object containing the user details.
{ "user": { "_id": "user_id_here", "fullname": { "firstname": "John", "lastname": "Doe" }, "email": "[email protected]", "socketId": null } }
- Status Code:
401 Unauthorized
- Body: A JSON object containing an error message.
{ "message": "Unauthorized" }
- Ensure that the
Authorization
header is set toBearer jwt_token_here
when making the request.
GET /users/logout
This endpoint allows an authenticated user to log out by invalidating their token.
Authorization
: A string containing the Bearer token.
Example:
Authorization: Bearer jwt_token_here
- Status Code:
200 OK
- Body: A JSON object containing a success message.
{ "message": "Logged out successfully" }
- Status Code:
401 Unauthorized
- Body: A JSON object containing an error message.
{ "message": "Unauthorized" }
- Ensure that the
Authorization
header is set toBearer jwt_token_here
when making the request.
POST /captain/register
This endpoint allows a new captain to register by providing their first name, last name, email, password, and vehicle details. The password will be hashed before storing in the database.
The request body should be a JSON object with the following properties:
fullname
: An object containing:firstname
: A string representing the captain's first name (minimum 3 characters).lastname
: A string representing the captain's last name (minimum 3 characters).
email
: A string representing the captain's email (must be a valid email format).password
: A string representing the captain's password (minimum 5 characters).vehicle
: An object containing:color
: A string representing the vehicle's color (minimum 3 characters).plate
: A string representing the vehicle's plate number (minimum 3 characters).capacity
: A number representing the vehicle's capacity (minimum 1).vehicleType
: A string representing the vehicle's type (must be one of "car", "motorcycle", "auto").
Example:
{
"fullname": {
"firstname": "Jane",
"lastname": "Doe"
},
"email": "[email protected]",
"password": "password123",
"vehicle": {
"color": "Red",
"plate": "XYZ123",
"capacity": 4,
"vehicleType": "car"
}
}
- Status Code:
201 Created
- Body: A JSON object containing the authentication token and captain details.
{ "token": "jwt_token_here", "captain": { "_id": "captain_id_here", "fullname": { "firstname": "Jane", "lastname": "Doe" }, "email": "[email protected]", "vehicle": { "color": "Red", "plate": "XYZ123", "capacity": 4, "vehicleType": "car" }, "socketId": null, "status": "inactive" } }
- Status Code:
400 Bad Request
- Body: A JSON object containing an array of validation error messages.
{ "errors": [ { "msg": "Invalid email", "param": "email", "location": "body" }, { "msg": "Name must be at least 3 characters long", "param": "fullname.firstname", "location": "body" }, { "msg": "Password must be at least 5 characters long", "param": "password", "location": "body" }, { "msg": "Color must be at least 3 characters long", "param": "vehicle.color", "location": "body" }, { "msg": "Plate must be at least 3 characters long", "param": "vehicle.plate", "location": "body" }, { "msg": "Capacity must be a number", "param": "vehicle.capacity", "location": "body" }, { "msg": "Vehicle type must be one of 'car', 'motorcycle', 'auto'", "param": "vehicle.vehicleType", "location": "body" } ] }
- Status Code:
400 Bad Request
- Body: A JSON object containing an error message.
{ "message": "All fields are required" }
- Ensure that the
Content-Type
header is set toapplication/json
when making the request. - The password is hashed before being stored in the database for security purposes.
POST /captain/login
This endpoint allows an existing captain to log in by providing their email and password.
The request body should be a JSON object with the following properties:
email
: A string representing the captain's email (must be a valid email format).password
: A string representing the captain's password (minimum 5 characters).
Example:
{
"email": "[email protected]",
"password": "password123"
}
- Status Code:
200 OK
- Body: A JSON object containing the authentication token and captain details.
{ "token": "jwt_token_here", "captain": { "_id": "captain_id_here", "fullname": { "firstname": "Jane", "lastname": "Doe" }, "email": "[email protected]", "vehicle": { "color": "Red", "plate": "XYZ123", "capacity": 4, "vehicleType": "car" }, "socketId": null, "status": "inactive" } }
- Status Code:
400 Bad Request
- Body: A JSON object containing an array of validation error messages.
{ "errors": [ { "msg": "Invalid email", "param": "email", "location": "body" }, { "msg": "Password must be at least 5 characters long", "param": "password", "location": "body" } ] }
- Status Code:
400 Bad Request
- Body: A JSON object containing an error message.
{ "message": "Invalid credentials" }
- Ensure that the
Content-Type
header is set toapplication/json
when making the request.
GET /captain/profile
This endpoint allows an authenticated captain to retrieve their profile information.
Authorization
: A string containing the Bearer token.
Example:
Authorization: Bearer jwt_token_here
- Status Code:
200 OK
- Body: A JSON object containing the captain details.
{ "captain": { "_id": "captain_id_here", "fullname": { "firstname": "Jane", "lastname": "Doe" }, "email": "[email protected]", "vehicle": { "color": "Red", "plate": "XYZ123", "capacity": 4, "vehicleType": "car" }, "socketId": null, "status": "inactive" } }
- Status Code:
401 Unauthorized
- Body: A JSON object containing an error message.
{ "message": "Unauthorized" }
- Ensure that the
Authorization
header is set toBearer jwt_token_here
when making the request.
GET /captain/logout
This endpoint allows an authenticated captain to log out by invalidating their token.
Authorization
: A string containing the Bearer token.
Example:
Authorization: Bearer jwt_token_here
- Status Code:
200 OK
- Body: A JSON object containing a success message.
{ "message": "Logged out successfully" }
- Status Code:
401 Unauthorized
- Body: A JSON object containing an error message.
{ "message": "Unauthorized" }
- Ensure that the
Authorization
header is set toBearer jwt_token_here
when making the request.
GET /ride/fare
This endpoint allows users to get the fare estimate for a ride based on the pickup and destination locations.
The request should include the following query parameters:
pickup
: A string representing the pickup location.destination
: A string representing the destination location.
Example: GET /ride/fare?pickup=location1&destination=location2
- Status Code:
200 OK
- Body: A JSON object containing the fare estimate for different vehicle types.
{ "auto": 50.0, "car": 100.0, "motorcycle": 30.0 } { "errors": [ { "msg": "Invalid pickup location", "param": "pickup", "location": "query" }, { "msg": "Invalid destination location", "param": "destination", "location": "query" } ] }
{ "message": "Missing pickup or destination" }