Java Micronaut REST API
🕓 45 minutes
#
What you’ll learnHow to setup your application for :
- getting data from REST API,
- providing data to REST API.
In this tutorial, we will create a simple Java component with the Java Micronaut scaffolder. We want to expose the single REST endpoint for getting user details for his username only. This will require simple sequential orchestration of two REST services, one to get user authorization privileges and second for basic user details.

#
Project sourceThis example project can be cloned from: http://gitlab.factory.codenow-control.codenow.com/public-docs/client-authorization-demo/client-info-service.git
#
Prerequisites- Prepare your local development environment for CodeNOW with Micronaut.
- Follow the tutorial instructions in the Java Micronaut Local Development tutorial.
- Create a new component
- For details, see the section Prerequisites of the Java Micronaut Local Development tutorial.
#
StepsOpen your IDE, import the created component and start coding:
Define the message payload. Here is an example of the GetClientInfoResponse, which is a simple POJO with basic user details and roles:
Generate getters and setters with your IDE.
Examples of GetClientDataResponse and GetClientRolesResponse can be found in the example project repository.
Next, create http clients for calling the orchestrated endpoints. Example for ClientDataServiceClient:
The second required client ClientAuthorizationServiceClient can be found in the example project repository
For more details about Micronaut clients: https://docs.micronaut.io/latest/guide/index.html#httpClient
Create a new Java interface:
Create a new controller and put all the parts together
For more details, see https://docs.micronaut.io/latest/guide/index.html#httpServer
Do not forget to change the swagger.yaml. Check it in the example project: src/main/resources/META-INF/swagger/swagger.yaml
Try to build and run the application in your IDE. After startup, you should be able to access your new controller’s swagger: http://localhost:8080/swagger/index.html
- For the correct setup, check the Readme.md in the project root or see the tutorial Java Micronaut Local Development, section Prepare local development IDE
- The component exposes a simple GET endpoint and can be tested using a browser call only. You should not forget to document your API and use the swagger-ui accordingly.

#
Deploy to CodeNOWIf your code works in the local development, you are ready to push your changes to GIT and try to build and deploy your new component version to the CodeNOW environment.
- For more information about application deployment see Application Deployment and Deployment Monitoring tutorials.
#
What`s next?See our other developer guides: