When learning any new framework, it always starts with building your first “Hello World” application. In Micronaut, this is incredibly simple, but also very powerful because you start using its key features like:
- Controllers
- Routing
- Dependency Injection
- Auto-generated boilerplate
In this post, you’ll learn how to create your first endpoint in Micronaut step-by-step using very simple language — even if you’re completely new to Micronaut or web development.
What is an Endpoint in Micronaut?
In simple words:
An endpoint is a URL path that your application listens to. When someone visits that path, your application returns a response.
Example:
- You visit:
http://localhost:8080/hello
- You get response:
Hello, World!
That’s what we are going to build.
Go through Installing Micronaut CLI and Setting Up Your First Project for setting up the micronaut env.
Step 1 — Create Your Micronaut Project
We will use Micronaut CLI to create the project:
1 2 3 4 |
mn create-app com.kscodes.micronaut.helloworld --build=maven --lang=java |
Explanation:
com.kscodes.micronaut.helloworld
: This is the package name.--build=maven
: We are using Maven.--lang=java
: We are using Java.
✅ After running this, Micronaut will automatically create a full project structure for you.
Step 2 — Understand Where to Write Code
Inside the generated project, navigate to:
1 2 3 4 |
src/main/java/com/kscodes/micronaut/helloworld/ |
This is where we will add our code.
You will already see a file Application.java
which looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 |
package com.kscodes.micronaut.helloworld; import io.micronaut.runtime.Micronaut; public class Application { public static void main(String[] args) { Micronaut.run(Application.class, args); } } |
This is your application’s entry point — Micronaut automatically starts the application from here.
Step 3 — Create Your First Controller
A controller is where you define endpoints.
Create a new Java file:
HelloController.java
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package com.kscodes.micronaut.helloworld; import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; @Controller("/hello") public class HelloController { @Get("/") public String sayHello() { return "Hello, World!"; } } |
Explanation (in very simple words):
Annotation | Meaning |
---|---|
@Controller("/hello") | This class handles requests that start with /hello . |
@Get("/") | This method handles GET requests sent to /hello/ . |
sayHello() | The method returns the text "Hello, World!" . |
✅ So when someone visits http://localhost:8080/hello/
, they will see:
Hello, World!
Step 4 — Run Your Application
Use the following command to start the server:
1 2 3 4 5 |
mvnw mn:run |
Micronaut will start your application and listen on port 8080
by default.
You should see something like:

Step 5 — Test Your Endpoint
Open your browser or use a tool like Postman or curl.
URL:
1 2 3 4 |
http://localhost:8080/hello/ |
Expected Output:
Hello, World!
🎉 Congratulations! You just built and ran your first Micronaut endpoint.
Step 6 — Customize the Endpoint
You can modify the controller to make it even more dynamic.
Updated Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
package com.kscodes.micronaut.helloworld; import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; import io.micronaut.http.annotation.PathVariable; @Controller("/hello") public class HelloController { @Get("/{name}") public String sayHello(@PathVariable String name) { return "Hello, " + name + "!"; } } |
Now if you visit:
1 2 3 4 |
http://localhost:8080/hello/KSCodes |
You’ll see:
Hello, KSCodes!
✅ You have now built a dynamic endpoint using path variables.
Quick Recap
Task | What You Learned |
---|---|
Create Project | Using Micronaut CLI |
Controller | Handling requests with annotations |
Endpoint | Return simple text responses |
Dynamic Input | Use of path variables |
Conclusion
Micronaut makes it super easy to build REST APIs and microservices, even for absolute beginners. With just a few lines of code, you have created a fully functional web service that responds to HTTP requests.
In upcoming tutorials, you can explore:
- Handling query parameters
- Returning JSON responses
- Adding database connections
- Securing your endpoints
- Testing your application
Reference : Micronaut Docs