Creating REST Service with Spring Boot

This guide will help you create and learn Simple REST service using Spring Boot.

We will create simple Rest Service Here in this lesson using Spring Boot

Tools you will need

Maven 3 – Build Tool

Eclipse – Our Fav IDE

JDK 1.8

Spring Boot

What is REST?

REST is an architectural style for designing distributed systems. It is not a standard but a set of constraints, such as being stateless, having a client/server relationship, and a uniform interface. REST is not strictly related to HTTP, but it is most commonly associated with it.

Following are the Set Of Constraints a REST Service must have:-

Server:- Which delivers a service

Client:- Entity which consumes the service

Service is Always Stateless

What Do We Create?

In order to create rest services, we need to declare some endpoints for spring Rest.A Simple rest service with following Endpoints:-

Type

End Point

Description

POST

/Users

save or add a user

GET

/Users

get list of all users

Every Rest endpoint needs a type associated with that. In this Rest Service with Spring Boot we are using POST and GET, there are other Http types as well such as PUT, DELETE, CONNECT, OPTIONS, HEAD.

Why Do we need these different types?

They are basically known as request methods which are treated as an indicator to our server to perform some specific set of Actions. To Understand more about these Click Here

Whooh! Let’s Create Our First Rest Service With Spring Boot !!

Create Rest Service With Spring Boot is Super easy. Let’s Open this Url in your Browser Click Here

It will Open Something Like in image shown below, enter the dependency as Web, package name as com.frugalis , enter any name of your choice in the name field and then click on Generate Project.

Project Structure:-

RestApplication.Java:-

The main method contains run() method which executes and start the spring boot.We don’t need any external tomcat as spring boot has its embedded tomcat. Once we run this Java class embedded tomcat is started.

We have used @ComponentScan(basePackages=”com.frugalis”), this annotation tells spring to scan spring beans from the specified package and load into memory.