A complete Ride Sharing Backend API built using Spring Boot, MongoDB, JWT Authentication, Input Validation, and Global Exception Handling.
This project supports user registration, login, ride booking, driver acceptance, and ride completion with role-based access.
- Java 17
- Spring Boot 3.2.5
- MongoDB
- Spring Security
- JWT Authentication
- Hibernate Validator
- Maven
- Tomcat Embedded Server
src/main/java/com/Sanskriti/Rapido/
βββ model/
βββ repository/
βββ service/
βββ controller/
βββ config/
βββ dto/
βββ exception/
βββ util/
- ROLE_USER β Passenger
- ROLE_DRIVER β Driver
- User Registration (BCrypt password encryption)
- User Login with JWT Token
- Role-based access control
- User can request a ride
- Driver can view all pending rides
- Driver can accept a ride
- User/Driver can complete a ride
- User can view their own rides
- JWT authentication on every secured API
- Stateless authentication
- Custom JWT filter
- DTO based validation
- Global exception handling
- Meaningful API error responses
Login β Receive JWT Token β Add Token in Header β Access Protected APIs
Authorization: Bearer <your-token>
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register user/driver |
| POST | /api/auth/login |
Login and get JWT |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/rides |
Request a ride |
| GET | /api/v1/user/rides |
View own rides |
| POST | /api/v1/rides/{id}/complete |
Complete ride |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/driver/rides/requests |
View pending rides |
| POST | /api/v1/driver/rides/{id}/accept |
Accept a ride |
{
"username": "john",
"password": "1234",
"role": "ROLE_USER"
}{
"username": "john",
"password": "1234"
}{
"pickupLocation": "Koramangala",
"dropLocation": "Indiranagar"
}curl -X POST http://localhost:9000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"john","password":"1234","role":"ROLE_USER"}'curl -X POST http://localhost:9000/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"driver1","password":"abcd","role":"ROLE_DRIVER"}'curl -X POST http://localhost:9000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"john","password":"1234"}'curl -X POST http://localhost:9000/api/v1/rides \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"pickupLocation":"A","dropLocation":"B"}'- MongoDB (Local)
- Collections:
usersrides
- Install Java 17
- Install and start MongoDB
- Clone the repository
- Open in IntelliJ IDEA
- Run:
mvn spring-boot:run
- Server runs at:
http://localhost:9000
Below are the screenshots of API testing done using Postman / Curl:
- User Registration Working
- JWT Login Working
- Ride Request Working
- Driver Accept Working
- Ride Completion Working
- Role Authorization Working
Sanskriti
Backend Developer β Spring Boot & MongoDB
GitHub: https://github.com/Sanskriti10247