Creating REST API in spring boot – Part1

In part1 of the series we will talk about setting up the spring boot application. You may consider this post as Hello world of Spring boot.

Spring boot reduces a lot of boiler plate codes necessary for your web application and it’s pretty easy to make a Micro service.

Visit Spring boot initializer to create and download a bare-bone application with required dependencies

We need to select Maven (you may choose gradle as well). select latest stable version of Spring boot.

Enter a group and artifact id.

Leave the dependencies section as we will add it manually and click on generate project.

This should download a zip file which will contain a spring boot project. Open it in your IDE and edit pom file to have below dependencies

<dependency>
<!-- Actuator provides various monitoring services for your application -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<!-- below dependencies are added for testing and details will be explained in related posts -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-reflect</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.14.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>

Complete pom file is available here

Download Category.JSON and Quotes.JSON and paste it to directory src//main/resources. These files contains static data for available categories of Quotes and Quotes itself

In next post we will read these json file to create a list of categories and quotes and expose API functions to access them.

Leave a comment

Your email address will not be published. Required fields are marked *