This is my solution for the TradeMap Code backend challenge. It's a comprehensive REST API that simulates a backend service for a personal blog platform.
Key features:
- Input validation for post request payloads.
- Full CRUD operations for posts.
- Pagination support with flexible sorting.
- Swagger documentation for all endpoints.
- One-command deployment with Docker Compose
For Docker (Recommended):
- Docker & Docker Compose
For Local Development:
- Java 21+
- Maven 3.9+
- MongoDB
Using Docker, .env file is optional since default values exist in Docker Compose file. For
local development without Docker, you must set MONGO_USER and MONGO_PASSWORD environment variables to
connect to your MongoDB instance properly. Other variables have sensible fallback defaults in the application
configuration.
Rename .env.example to .env and modify variables according to your needs.
| Variable | For Docker | For Local Development | Description |
|---|---|---|---|
| PORT | Optional (Default: "8080") | Optional (Default: "8080") | Server port |
| MONGO_USER | Optional (Default: "trademap") | Required | MongoDB username |
| MONGO_PASSWORD | Optional (Default: "dbpassword") | Required | MongoDB password |
| MONGO_DATABASE | Optional (Default: "posts") | Optional (Default: "posts") | MongoDB database |
For the fastest setup, it is recommended to use Docker Compose to start the app and its services:
# Run docker compose command to start all services
$ docker compose up -d --buildAccess the application at http://localhost:8080/api/v1/posts (or the port you configured).
| Route | HTTP Method | Params | Description | Auth Method |
|---|---|---|---|---|
/docs |
GET | - | Swagger documentation | None |
/api/v1/posts |
POST | Body with title, description and body. |
Create a new post | None |
/api/v1/posts |
GET | Query Parameters: • page - Page number (default: 0)• size - Page size (default: 10)• orderBy - Sort field (default: "title")• direction - Sort direction: ASC/DESC (default: "ASC") |
Retrieve paginated posts with sorting | None |
/api/v1/posts/:id |
GET | :id |
Retrieve existing post by its unique id. | None |
/api/v1/posts/:id |
PUT | :id + Body with title, description and body. |
Update post information | None |
/api/v1/posts/:id |
DELETE | :id |
Delete an existing post. | None |
POST /api/v1/posts
Request body:
{
"title": "Getting Started with Spring Boot",
"description": "A comprehensive guide to building REST APIs with Spring Boot framework.",
"body": "Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications."
}PUT /api/v1/posts/:id
Request body:
{
"title": "Getting Started with Spring Boot",
"description": "A comprehensive guide to building REST APIs with Spring Boot framework.",
"body": "Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications."
}