1
0
Fork
You've already forked hello-micronaut
0
An example project to explore Micronaut as an alternative to Spring for building microservices
  • Java 100%
2021年04月11日 08:44:52 +03:00
gradle/wrapper Create project 2021年04月10日 09:58:53 +03:00
src Refactor: extract query building to separate class 2021年04月11日 08:44:52 +03:00
.gitignore Create project 2021年04月10日 09:58:53 +03:00
build.gradle Add test for mapping on employee create 2021年04月11日 08:17:09 +03:00
gradle.properties Configure OpenAPI/Swagger 2021年04月10日 14:52:33 +03:00
gradlew Create project 2021年04月10日 09:58:53 +03:00
gradlew.bat Create project 2021年04月10日 09:58:53 +03:00
LICENSE Create project 2021年04月10日 09:58:53 +03:00
micronaut-cli.yml Implement persistence 2021年04月10日 14:17:41 +03:00
openapi.properties Configure OpenAPI/Swagger 2021年04月10日 14:52:33 +03:00
README.md Document position filtering 2021年04月10日 18:57:15 +03:00
settings.gradle Create project 2021年04月10日 09:58:53 +03:00

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

  1. 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
    
  2. Run the project
    ./gradlew run
    

The tests run on H2.

How to use

An example scenario would be:

  1. 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"
    }'
    
  2. 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日"
    }'
    
  3. 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日"
    }'
    
  4. List employees
    curl --location --request GET 'http://localhost:8080/employee?sort=name&order=desc&offset=0&max=2'
    
    • All query parameters are optional.
  5. 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'
    

API