DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Growth and Demand for Low Code Development
  • Modernizing a Legacy Java Application With OpenRewrite: What We Automated and What We Didn't
  • Idempotency Under Concurrency: Why Your Application Check Isn't the Last Line of Defense
  • Running a Self-Hosted WAF in Production: Practical Lessons From SafeLine

Trending

  • Getting Started With Qdrant: Building Intelligent Search Applications With Java
  • Observability With AI SREs: A 4-Step Implementation Guide
  • Deny by Default: Policy-as-Code Guardrails for Agents That Act
  • What 55 Runs Taught Me About Memory in AI Coding Agents

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Culture and Methodologies
  3. Methodologies
  4. Micronaut: Rapid Development With MicrostarterCLI

Micronaut: Rapid Development With MicrostarterCLI

MicrostarterCLI is a rapid development tool for Micronaut applications. In this article, we will demonstrate how it makes developing GraphQL services easy.

By 
Ahmed Al-Hashmi
·
Apr. 18, 22 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
7.0K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

MicrostarterCLI is a rapid development tool for Micronaut applications. It helps you as a developer to generate standard reusable codes, configurations, or patterns as you need in your application. 

Application Description

In this article, we will develop an ArabicNames service that has REST and GraphQL endpoints. To begin with the development, we will generate a Micronaut application project from Micronaut Launch. Then, we will use MicrostarterCLI to develop the following: 

  1. ArabicName entity class.
  2. JDBC repository and Service classes for the Arabic Entity Class. 
  3. REST and GraphQL endpoints to consume the Arabic Name services.
  4. Liquibase migration file.
  5. TestClass to test Arabic Name REST endpoints.

ArabicName Entity Attributes

Attribute
Data Type description
letter String English letter
name String The name in English
nativeArabic String The name is Arabic
meaning String The name's meaning in English

Let's Do It 

Step 1:  Visit https://micronaut.io/launch and generate a Micronaut application with a language of your choice. You can add the features you need for the Arabic Names service, but MicrostarterCLI will add all the required features if you don't add them from Micronaut Launch. 

In this article, I'll generate the project as follows: 

Micronaut Application
Application Type
Micronaut Application
Java Version
11
Name
ArabicNames
package
io.hashimati.dzone
Micronaut Version
Latest
language
Java
Build Tool
Gradle
Test Framework
JUnit

Step 2: Download the MicrostarterCLI release zip file. Then, unzip it and copy the mc.jar, mc.bat, and mc files to the root of the project's folder. 

https://github.com/hashimati/MicrostarterCli/releases/tag/v0.1.1

Step 3: Go to the project directory from the terminal/command prompt and run the "configure" command: 

Shell
 
mc configure

The "configure" command will take you through a step-by-step process to add the project's dependencies with their necessary configuration and the database information. The dependencies include:

  • Port Number: The default port value is 8080
  • Reactive Framework: Reactor, RxJava2, or RxJava3
  • Database Type Dependencies: MongoDB, H2, MySQL, Oracle, MariaDB, Postgres, or SQL Server  
  • Database Access Framework: Micronaut Data, ReactiveMongo, or Gorm
  • Database Migration Tool: Liquibase or Flyway
  • Messaging: Kafka, RabbitMQ, NATs.io, or GCP-PubSub 
  • Caching: Caffeine
  • Micrometers
  • Tracing: Jaeger or Zipkin
  • GraphQL: GraphQL Java Kickstart
  • OpenAPI: MicrostarterCLI will add this dependency by default. 

We will do the configuration as follows:

Step 4: Run the "entity" command to generate the ArabicName's entity, repository, service, controller, test-controller, client, GraphQL files, and Liquibase files.

Shell
 
mc entity -e ArabicName --graphql

When the command starts, it will ask you to enter the collection's name or the table. Then, it will prompt you to enter the attributes. Add the attributes as the following table: 

Attribute Type Validation FindBy() Method FindAllBy() Method UpdateBy() Method
Name String - Yes No Yes
letter String - No Yes No
NativeArabic String - Yes No No
Meaning String - No No No

Step 5: Open the project with your favorite IDE and check the generated files.

Step 6: Run the "gradlew test" command to run a JUnit test for the ArabicName REST endpoints. 

Shell
 
gradlew test

Step 7: Run the "gradlew run" command to run the application.  

Step 8: Try the REST services using OpenAPI. The OpenAPI is accessible on this URL: http://localhost:8080/swagger/views/swagger-ui/index.html. 

We will save the below object by calling "http://localhost:8080/api/v1/arabicName/save".

 
{
	"name": "Abbas",
	"letter": "A",
	"nativeArabic": "عباس",
	"meaning": "Another name for a lion. The lion that the lions flee from"
}

Step 9: Try the GraphQL services. Open "http://localhost:8080/graphiql". Retrieve all Arabic Names objects by calling the below query.

Markdown
 
query{
  findAllArabicName{
    name, 
    letter, 
    nativeArabic, 
    meaning
  }
}


Conclusion

MicrostarterCLI is a progressive rapid development tool, and it has a lot of features that cut development time and remove the burden of the configuration. I'll try to cover the MicrostarterCLI features in more depth in subsequent articles. The source code for this project is available here. 

Happy coding!

Rapid application development application

Opinions expressed by DZone contributors are their own.

Related

  • Growth and Demand for Low Code Development
  • Modernizing a Legacy Java Application With OpenRewrite: What We Automated and What We Didn't
  • Idempotency Under Concurrency: Why Your Application Check Isn't the Last Line of Defense
  • Running a Self-Hosted WAF in Production: Practical Lessons From SafeLine

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook