Spring Boot With Kotlin. Create a Project With a Simple HTML Page and API Endpoints in Examples

Artem Diashkin
Mar 17 · 5 min read

Here we will take a look at how we can create a simple Spring Boot application in a few seconds using Spring initializr, how we can create a simple HTML page and API Endpoints.

⚠️ NOTE: If you are not familiar with Kotlin — don’t worry, IntelliJ IDE will help you convert Java to Kotlin, and if you are familiar with Java, → you will see how more compact our code could look like with Kotlin.

Spring initializr

How can we easily create our project with all configurations, dependencies, language versions, app builder, etc.?

Fortunately, Spring Framework provides Spring Boot initializr. On that platform, you can select what you need and initialize will do the rest for you. We can download generated archive, or we can use IntelliJ IDE that will do the same:

Creating a Spring Boot project

So, let’s begin our journey from the easiest part → creating a Spring Boot project in 5 steps:

Step 1: Click on “New project”:

Step 2: Select JDK version (I will use 1.8):

Step 3: Type some info about your project:

  • Type — Gradle (what tool will build are project);
  • Language — Kotlin;
  • Java version — 8;

Step 4: Add Spring Web dependency to your project:

Step 5: Set Project name (I typed spring-boot-demo, but you can choose any name you like) and don't forget to specify proper Project location 🙂;

That’s it, your project is created, configured, and ready to run! Cool 🎉

⚠️ NOTE: If Gradle not installed globally, don’t worry, it will be included in your project by Spring Boot Initializr:

If you are not familiar with Gradle you can check here (if you worked on Node.js projects → this is like yarn or npm):

You can find a version of your local Gradle in the gradle-wrapper.properties file:

To run your project you can run ./gradlew bootRun command in the root folder of your project or just press Run in IntelliJ IDEA:

After the run command, you will see log info in your terminal with the port of your project (it can be changed inside the application.properties file)…

Tomcat started on port(s): 8080 (http) with context path ''

… so you can open localhost:8080 page in your browser and see this result:

All works, awesome! 🎉

⚠️ NOTE: If you are curious about how your project will look like after build (folder structure, generated files, etc), you can run ./gradlew build CLI command:

Creating starter HTML page

Before we will work on GET Endpoint, let’s take a look at how easily you can create a starter page without any configuration, you need to create an HTML file inside the src/main/resources/static folder:

Re-run your project and that’s it, no config required, Spring Boot will understand you without words 🙂

Creating endpoints

For our endpoints, we will need to create a Kotlin Class that will be our Controller:

As you probably noticed we added “additional info”/Annotations to our class and function, those will tell Spring Boot: “You should use this class as a Controller, and please return a string on GET /hello endpoint”

⚠️ NOTE: You can pass additional params to the @RequestMapping annotation:

@RequestMapping(
value = "/hello/api/version",
method = {
RequestMethod.PUT,
RequestMethod.POST
} )

You can check more about it here:

Re-run your project and see some magic 🧙‍♂️

Let’s create a few more endpoints:

User class (can be a Model in a database in the future, who knows 🤷‍♂️)

Re-run project:

⚠️ NOTE: In IntelliJ IDE you can test your endpoints without opening your browser or without Postman etc.., but by using Endpoints tab → HTTP Client

Hope now you see how easy it can be! Happy coding

LITSLINK

LITSLINK’s team is sharing their experience

By LITSLINK

It's a test newsletter! Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Artem Diashkin

Written by

Java, Spring, Node.js, AdonisJs, React.js and Flutter developer

LITSLINK

LITSLINK

Hands-on up to date experience sharing of the most skilled & talented software developers right here, right now. Subscribe to learn & understand more about the Software World.

Artem Diashkin

Written by

Java, Spring, Node.js, AdonisJs, React.js and Flutter developer

LITSLINK

LITSLINK

Hands-on up to date experience sharing of the most skilled & talented software developers right here, right now. Subscribe to learn & understand more about the Software World.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store