REST API for managing feature flags — create and evaluate flags by key, with validation, duplicate detection, and one-command run via Docker Compose.
Features • Architecture • Quick Start • API • Tech Stack
| Feature | Description |
|---|---|
| Create flags | POST /api/flags with key, optional description and status; returns 201 with full flag payload. |
| Get by key | GET /api/flags/{key} returns the flag or 404 if not found. |
| Unique keys | Duplicate key on create returns 409 Conflict; DB unique index on flagKey. |
| Bean Validation | Request DTOs validated with Jakarta Validation; blank or invalid key yields 400. |
| JPA persistence | Flags stored in H2 (in-memory by default); schema via Hibernate DDL; easy to switch to PostgreSQL. |
| Status lifecycle | Enum-based status: CREATED, ENABLED, DISABLED; default CREATED when omitted. |
| Docker Compose | Single command builds and runs the app; no local JDK required. |
| Tests | Unit tests for service (Mockito); slice tests for controller (@WebMvcTest). |
| Actuator | Health and info endpoints for monitoring. |
flowchart LR
subgraph Client
C[HTTP Client]
end
subgraph "Spring Boot :8081"
REST[REST API]
REST --> Svc[FlagService]
Svc --> Repo[FlagRepository]
end
subgraph "H2"
DB[(flags table)]
end
C -->|"GET /api/flags/:key"| REST
C -->|"POST /api/flags"| REST
Repo --> DB
Flow: Clients create flags via POST /api/flags (JSON body). Service checks uniqueness, persists via JPA, returns 201 or 409. GET /api/flags/{key} reads from the repository and returns 200 or 404.
git clone https://github.com/NullPoint3rDev/feature-flags-microservice.git
cd feature-flags-microservice
docker compose up --buildAPI base: http://localhost:8081
# Create a flag
curl -X POST http://localhost:8081/api/flags \
-H "Content-Type: application/json" \
-d '{"key": "dark-mode", "description": "Dark theme toggle", "status": "CREATED"}'
# Get flag by key
curl http://localhost:8081/api/flags/dark-mode./gradlew bootRunRuns on http://localhost:8081. H2 console (if enabled): http://localhost:8081/h2-console.
| Method | Path | Description |
|---|---|---|
POST |
/api/flags |
Create a flag. Body: { "key": "string", "description": "optional", "status": "CREATED|ENABLED|DISABLED" }. Returns 201 or 409 (duplicate key), 400 (validation). |
GET |
/api/flags/{key} |
Get flag by key. Returns 200 + JSON or 404. |
{
"flagId": "3b71566c-d2df-4a8b-9e00-3e930d564903",
"flagKey": "dark-mode",
"flagStatus": "CREATED",
"flagDescription": "Dark theme toggle",
"flagRules": null
}| Technology | Purpose |
|---|---|
| Java 21 | LTS runtime. |
| Spring Boot 3.2 | Web, Actuator, Validation, Data JPA. |
| Spring Data JPA | Repository abstraction; H2 driver for in-memory DB. |
| H2 | Embedded DB; optional console for debugging. |
| Gradle 8.x (Kotlin DSL) | Build and dependency management. |
| Docker & Compose | Single-command run; multi-stage Dockerfile (JDK build, JRE run). |
| JUnit 5 & Mockito | Unit and controller slice tests. |
| Lombok | Boilerplate reduction on entities and DTOs. |
This project is licensed under the MIT License.