An example project to explore Micronaut as an alternative to Spring for building microservices
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Cosmin Humeniuc 19535ca0a0
Refactor: extract query building to separate class
4 weeks ago
gradle/wrapper Create project 4 weeks ago
src Refactor: extract query building to separate class 4 weeks ago
.gitignore Create project 4 weeks ago
LICENSE Create project 4 weeks ago
README.md Document position filtering 4 weeks ago
build.gradle Add test for mapping on employee create 4 weeks ago
gradle.properties Configure OpenAPI/Swagger 4 weeks ago
gradlew Create project 4 weeks ago
gradlew.bat Create project 4 weeks ago
micronaut-cli.yml Implement persistence 4 weeks ago
openapi.properties Configure OpenAPI/Swagger 4 weeks ago
settings.gradle Create project 4 weeks ago

README.md

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