This documentation details the RESTful API endpoints for the Sarthi microservices ecosystem.
The Base URL depends on the service you are accessing:
- Auth Service:
/api(Port 5001 / 5002) - Ride Service:
/api(Port 5003) - Marketplace Service:
/api(Port 5000)
Most endpoints require a JWT token. Pass it in the header:
Authorization: Bearer <your_jwt_token>Authenticates a user via Google OAuth. Creates a new user if one doesn't exist.
Body:
{
"tokenId": "google_id_token_string",
"role": "student" // Options: "student", "faculty", "staff"
}Response:
{
"success": true,
"token": "jwt_token_string",
"user": {
"_id": "user_id",
"email": "user@iiitg.ac.in",
"role": "student",
"fullName": "John Doe"
}
}Notes:
- Restricts login to
@iiitg.ac.indomains (except for admins). - Maps "staff" role to "admin" internally.
Fetches the currently logged-in user's profile.
Headers: Authorization required.
Response:
{
"success": true,
"user": { ...user_details }
}Updates the current user's profile. Allowed fields depend on the user's role.
Headers: Authorization required.
Body (Student):
{
"fullName": "...",
"rollNumber": "...",
"course": "...",
"department": "..."
}Body (Faculty):
{
"fullName": "...",
"department": "...",
"employeeId": "..."
}Body (Admin/Staff):
{
"fullName": "...",
"role": "...",
"staffId": "..."
}Response:
{
"success": true,
"user": { ...updated_user_details }
}Fetches all available rides.
Response: Array of ride objects.
Creates a new ride.
Headers: Authorization optional (Anonymous rides allowed, but owner info attached if token present).
Body:
{
"rideTitle": "Guwahati to IIITG",
"pickupLocation": "Paltan Bazar",
"dropoffLocation": "IIITG Campus",
"rideDate": "2023-11-25T10:00:00.000Z",
"availableSeats": 3,
"price": 500,
"description": "Leaving at 10 AM sharp."
}Sends a request to join a specific ride.
Headers: Authorization required.
Response: Returns the created request object.
Fetches incoming join requests for rides owned by the current user.
Headers: Authorization required.
Fetches outgoing join requests made by the current user.
Headers: Authorization required.
Fetches all requests with status accepted where the user is either the requester or the owner.
Headers: Authorization required.
Accept or reject a ride request.
Headers: Authorization required.
Body:
{
"status": "accepted" // or "rejected"
}Note: Accepting a request automatically creates a chat room between the two users and decrements available seats.
Fetches chat history for a specific chat room.
Headers: Authorization required.
Sends a message to a chat room.
Headers: Authorization required.
Body:
{
"text": "Hello!"
}Note: Emits real-time socket events (message) to the room.
Fetches all marketplace listings.
Headers: Authorization required.
Query Params: Optional filters (category, price, etc.) depending on controller implementation.
Creates a new marketplace listing.
Headers: Authorization required.
Body:
{
"title": "Bicycle",
"description": "Good condition",
"price": 3000,
"category": "Vehicles",
"condition": "Used",
"images": ["url1", "url2"],
"contactInfo": "9876543210"
}Fetches listings created by the current user.
Headers: Authorization required.
Fetches a single listing details.
Headers: Authorization required.
Updates a listing.
Headers: Authorization required.
Deletes a listing.
Headers: Authorization required.
Marks a listing as sold.
Headers: Authorization required.
Fetches the user's profile by proxying the request to the Auth Service.
Headers: Authorization required.
Fetches a history of items sold (listings created) by the user.
Headers: Authorization required.
All endpoints may return error responses in the following format:
{
"success": false,
"message": "Error description",
"error": "Detailed error message"
}Common HTTP status codes:
200: Success201: Created400: Bad Request401: Unauthorized403: Forbidden404: Not Found500: Internal Server Error
The Ride Service includes a Socket.IO server for real-time features.
Connect to the Socket.IO server:
const socket = io('http://localhost:5003', {
auth: {
token: 'your_jwt_token'
}
});Client → Server:
-
join-chat: Join a specific chat roomsocket.emit('join-chat', { chatId: 'chat_room_id' });
-
send-message: Send a message to a chat roomsocket.emit('send-message', { chatId: 'chat_room_id', text: 'Hello!' });
Server → Client:
-
message: Receive a new messagesocket.on('message', (data) => { console.log('New message:', data); });
-
ride-request-update: Notification when a ride request is accepted/rejectedsocket.on('ride-request-update', (data) => { console.log('Request status:', data.status); });
API endpoints are rate-limited to prevent abuse. If you exceed the rate limit, you'll receive a 429 Too Many Requests response.
For issues or questions about the API, please open an issue on the GitHub repository or contact the development team.