- Overview
- Architecture
- API Endpoints
- Authentication
- Getting Started
- Configuration
- Security Features
- Error Handling
- API Examples
- Development
- Contributing
- License
- Contact
Lets-Play REST API is a production-ready RESTFull service providing comprehensive user and product management. Built with Spring Boot and MongoDB, it enables high-performance CRUD operations with enterprise-grade security and JWT-based authentication.
Key Features:
- Full user management with role-based access control
- Product catalog with ownership tracking
- Token-based authentication using JWT
- Comprehensive error handling
- Rate limiting and CORS protection
- HTTPS and password encryption (BCrypt)
The API follows a layered architecture:
βββββββββββββββββββ
βββββββββββ β Controllers β ββββββββββββββββ
β Client βββββββ€ ββββββΊβ Security β
βββββββββββ ββββββββββ¬βββββββββ β Filters β
βΌ ββββββββββββββββ
βββββββββββββββββββ
β Services β
ββββββββββ¬βββββββββ
βΌ
βββββββββββββββββββ ββββββββββββββββ
β Repositories βββββββ€ MongoDB β
βββββββββββββββββββ ββββββββββββββββ
classDiagram
User "1" -- "n" Product : Owns
User : +String id
User : +String name
User : +String email
User : +String password
User : +String role
Product : +String id
Product : +String name
Product : +String description
Product : +Double price
Product : +String userId
| Method | Endpoint | Description | Access |
|---|---|---|---|
| POST | /api/auth/register |
Register new user | Public |
| POST | /api/auth/login |
Authenticate user | Public |
| GET | /api/users |
Get all users | Admin only |
| PUT | /api/users/{id} |
Update user info | Admin or Self |
| DELETE | /api/users/{id} |
Delete user | Admin or Self |
| Method | Endpoint | Description | Access |
|---|---|---|---|
| GET | /api/products |
List all products | Public |
| GET | /api/products/{id} |
Get product by ID | Public |
| POST | /api/products |
Create a product | Admin |
| PUT | /api/products/{id} |
Update product | Admin or Owner |
| DELETE | /api/products/{id} |
Delete product | Admin or Owner |
JWT-based authentication flow:
- Login generates a token
- Token structure:
- Header: Algorithm & type
- Payload: User ID, roles, expiration
- Signature: Ensures integrity
- Usage: Include in the header:
Authorization: Bearer <token> - Expiration: Tokens are valid for 1 hour (configurable)
- Java 17+
- MongoDB 5.0+
- Maven 3.8+
git clone https://learn.zone01dakar.sn/git/aliouniang/lets-play
cd lets-play
mvn clean package
java -jar target/lets-play.jarVisit http://localhost:8080/api/
Use application.properties or environment variables:
# Server
server.port=8443
server.servlet.context-path=/api
# MongoDB
spring.data.mongodb.uri=${MONGODB_URI}
spring.data.mongodb.database=${DB_NAME}
# JWT
jwt.secret=${JWT_SECRET}
jwt.expiration=3,600,000 # 1 hour
# HTTPS
server.ssl.enabled=true
server.ssl.key-store=classpath:localhost.p12
server.ssl.key-store-password=${KEY_STORE_PASSWORD}
server.ssl.key-store-type=PKCS12
server.ssl.key-alias=tomcat- BCrypt password hashing
- Input validation (anti-injection)
- HTTPS enforcement (prod)
- Role-based access control
- Rate limiting (100 req/min)
- CORS restrictions
- JWT-based session management
Errors follow a standard format:
{
"timestamp": "2023-05-14T15:32:18.456Z",
"status": 400,
"error": "Bad Request",
"message": "Email address already in use",
"path": "/api/auth/register"
}| Code | Description |
|---|---|
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 409 | Conflict (e.g., duplicate data) |
| 422 | Unprocessable Entity |
| 429 | Too Many Requests |
POST /api/auth/register
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com",
"password": "securePassword123"
}POST /api/auth/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "securePassword123"
}POST /api/products
Authorization: Bearer
Content-Type: application/json
{
"name": "Premium Headphones",
"description": "Noise cancelling bluetooth headphones",
"price": 199.99
}- Spring Boot 3.1.0
- MongoDB 6.0
- JWT Authentication
- Maven Build Tool
src/
βββ main/
β βββ java/com/yourcompany/api/
β β βββ config/
β β βββ controller/
β β βββ dto/
β β βββ exception/
β β βββ model/
β β βββ repository/
β β βββ security/
β β βββ service/
β β βββ Application.java
β βββ resources/
β βββ application.properties
β βββ logback.xml
βββ test/
- Fork this repo
- Create your branch:
git checkout -b feature/feature-name - Commit your changes:
git commit -m 'Add new feature' - Push your branch:
git push origin feature/feature-name - Open a Pull Request
Licensed under the MIT License.
Built with β€οΈ by Lino-Sn
- GitHub: @lino-smart
- Documentation: Spring Boot Reference Guide