Loading repository data…
Loading repository data…
tysker / repository
A lightweight REST API built with Spark Java, Hibernate, PostgreSQL, and JWT authentication. The project demonstrates clean backend architecture suitable for learning and teaching Java backend development.
A lightweight REST API built with Spark Java, Hibernate, PostgreSQL, and JWT authentication. The project demonstrates clean backend architecture suitable for learning and teaching Java backend development.
This project was built as an educational REST API to teach:
Everything is designed to be as easy to understand as possible.
Taken from your real pom.xml.
src/main/java/dk/lyngby/
│
├── config/ → EMF, ApplicationConfig
├── controller/ → Routes
├── exceptions/ → API exception handling
├── model/
│ ├── entities/ → JPA entities
│ ├── facade/ → DB logic
│ └── security/ → JWT, auth middleware
├── service/ → Business logic
│ ├── dto/
│ ├── AuthenticationService
│ ├── PersonService
│ └── Main → Application entry point
(public)
| Method | Endpoint | Description | Body |
|---|---|---|---|
| POST | /api/v1/login | Login & receive JWT | { "username": "", "password": "" } |
| POST | /api/v1/register | Register & receive JWT | { "username": "", "password": "", "role": "" } |
Middleware: before("/*", authentication::authenticate);
| Method | Endpoint | Description | Auth | Body |
|---|---|---|---|---|
| POST | /api/v1/persons/ | Create person | Yes | Person JSON |
| GET | /api/v1/persons/ | Get all persons | Yes | — |
| GET | /api/v1/persons/:id | Get person | Yes | — |
| PATCH | /api/v1/persons/:id | Update person | Yes | Person JSON |
| DELETE | /api/v1/persons/:id | Delete person | Yes | — |
(Directly extracted from your Routes.java.)
Client → Routes → Services → Facades → Hibernate/JPA → PostgreSQL
JWT middleware wraps all /persons routes.
A full Postman collection is included:
postman_collection.json
Features:
Import it in Postman and start testing immediately.
mvn clean package
Your JAR will be:
target/app.jar
docker build -t spark-api .
docker run -p 8080:8080 spark-api
docker compose up --build
This starts:
Integration tests use Testcontainers for PostgreSQL.
Run all tests:
mvn test
Login:
curl -X POST http://localhost:8080/api/v1/login \
-H "Content-Type: application/json" \
-d '{"username":"john","password":"test123"}'
MIT License.