Java Spring Boot REST API
🕓 45 minutes
#
What you’ll learn:How 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 Spring Boot 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 roles and the second for basic user details.

#
Project sourceThis example project can be cloned from: http://gitlab.factory.innobank.codenow.com/innobank/aia-spring-boot-rest-api.git
#
PrerequisitesPrepare your local development environment for CodeNOW with Spring Boot.
- Follow the tutorial instructions in the Java Spring Boot Local Development tutorial.
Create a new component.
- For details see the section Prerequisites of the Java Spring Boot Local Development tutorial.
#
StepsOpen your IDE, import the created component and start coding:
Define the message payload. Here is an example of ClientInfo, which is a simple POJO with basic user details and roles:
Generate getters and setters with your IDE.
Examples of the ClientData and ClientAuthorization classes can be found in the example project repository.
Next, create the classes ClientDataService and ClientAuthorizationService with the @Service annotation. These classes will represent http clients for calling the orchestrated endpoints. Example for ClientDataService:
For more details about Spring Boot @Service annotation, visit this page: https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/stereotype/Service.html
For more details about Spring Boot WebClients use this link: https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/html/boot-features-webclient.html
Create a new Java class:
In the baseUrl(), you should put the url to your existing component.
Create a new controller and put all parts together:
For more details about Spring Boot controllers, see: https://docs.spring.io/spring/docs/3.0.0.M4/reference/html/ch15s03.html
Create a new class ClientInfoController:
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 file in the project root or see the tutorial Java Spring Boot 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 the Application Deployment and Deployment Monitoring tutorials.
#
What’s next?See our other developer guides: