An example project to explore Micronaut as an alternative to Spring for building microservices
- Java 100%
| gradle/wrapper | Create project | |
| src | Refactor: extract query building to separate class | |
| .gitignore | Create project | |
| build.gradle | Add test for mapping on employee create | |
| gradle.properties | Configure OpenAPI/Swagger | |
| gradlew | Create project | |
| gradlew.bat | Create project | |
| LICENSE | Create project | |
| micronaut-cli.yml | Implement persistence | |
| openapi.properties | Configure OpenAPI/Swagger | |
| README.md | Document position filtering | |
| settings.gradle | Create project | |
Hello Micronaut
An example project to explore Micronaut as an alternative to Spring for building microservices.
This is a small Java service that exposes a RESTful API over CRUD operations on an employee model.
The model
- Employee
- name
- position
- superior (link to another employee with a management position)
- start date
- end date
How to run
- Run a Docker container with PostgreSQL
docker run -it --rm \ -p 5432:5432 \ -e POSTGRES_USER=dbuser \ -e POSTGRES_PASSWORD=theSecretPassword \ -e POSTGRES_DB=micronaut \ postgres:13.2-alpine - Run the project
./gradlew run
The tests run on H2.
How to use
An example scenario would be:
- Add two positions, "worker" and "manager"
curl --location --request PUT 'http://localhost:8080/position' \ --header 'Content-Type: application/json' \ --data-raw '{ "name": "worker" }'curl --location --request PUT 'http://localhost:8080/position' \ --header 'Content-Type: application/json' \ --data-raw '{ "name": "manager" }' - Add a manager
curl --location --request PUT 'http://localhost:8080/employee' \ --header 'Content-Type: application/json' \ --data-raw '{ "name": "Robinson", "position": 2, "startDate": "2021年04月10日", "endDate": "2021年12月31日" }' - Add a worker
curl --location --request PUT 'http://localhost:8080/employee' \ --header 'Content-Type: application/json' \ --data-raw '{ "name": "Friday", "position": 1, "superior": 3, "startDate": "2021年04月10日", "endDate": "2021年12月31日" }' - List employees
curl --location --request GET 'http://localhost:8080/employee?sort=name&order=desc&offset=0&max=2'- All query parameters are optional.
- List only employees with a specific position
curl --location --request GET 'http://localhost:8080/employee?position=1&sort=name&order=desc&offset=0&max=2'