Quick spring boot microservice API using Telosys generator

In this post, we are going to generate base spring boot Rest API microservice code using Telosys code generator.

When working in a microservices environment, it is quite common to create services with the same architecture. This means that a lot of time is wasted doing repetitive code before focusing on the business logic.

One practical solution is to set up a tool/mechanism that will allow to quickly create and update microservices with the common code base.

Telosys is a good choice to build the components of our microservices.

Prerequisites

This is the list of all the prerequisites for following this story:

  • Java 17
  • Spring Boot
  • Maven 3.6.3
  • Eclipse / STS
  • PostgreSQL
  • Postman

Overview

What is Telosys?

Telosys is a lightweight Open Source code generator. It allows to generate any kind of language (Java, Python, GoLang, PHP, JavaScript, TypeScript, C#, etc). It works without UML model and uses customizable templates to generate the code (templates syntax is based on Velocity).

Why use Telosys ?

  • It is open-source and free to use.
  • It is simple and easy to use either in an IDE or with a simple command line.
  • You can create and customize your own template.
  • It does not require a UML model.
  • Templates based on Velocity.
  • Model creation from database

Getting Started

Use case

In our case study, we have an existing relational database under Postgresql and we want to generate a REST API microservice with spring boot.

Step 1: “book-microservice” project creation

We will start by creating a simple Spring reactive project from start.spring.io, with the following dependencies: Spring Web, Spring data jpa, postgresql, and Validation.

Step 2: Telosys Initialization

Telosys allows to use all its features with a command line interface or an IDE plugin. For this story, we will use the Telosys Eclipse plugin because this plugin is very easy to use.

We have to install it from the Eclipse market.

Let’s initialize Telosys in our project.

Right-click on project > Properties > On the left panel, select Telosys Tools. Click the Initialize Telosys Tools button.

Telosys Tools directory is now added to the project :

The main part of Telosys setup is the template bundle. We need to install the template bundle into the project. For this, we have customized our own Rest API bundle template available on the spring-boot-telosys-template repository. We will clone the project into the templates folder.

Step 3: Database connection

In this step, we define the database connection file “databases.dbcfg”. Open the database configuration file TelosysTools/databases.dbcfg and create a new database configuration. Fill in all the database connection information and test it.

In Meta-data tab, load all the database schema and create model.

We see TelosysTools/POSTGRESQL.dbrep file.

Step 4: Code generation

We have finally arrived. We generate the source code of our project.

Open TelosysTools/POSTGRESQL.dbrep file and click on the “Code generation” tab.

In the dropdown list, select the templates bundle “spring-boot-telosys-template” which will be used for the generation.

Click on the “Generate” button

Our microservice is now ready.

Let’s try

Run the application and import the generated JSON collections into Postman.

Test Get all Authors

Congratulations! We have finished this story !!!!!.

Conclusion

In this story, we have generated a microservice Rest API without writing code with Telosys.

References

👉 Link to Medium blog

Related Posts