Creating a REST Service
Learn about the ease and simplicity of development using Spring Boot by creating a REST controller.
We'll cover the following...
Let’s have a look at how to create a REST service using Spring Boot. We will define a controller for movie recommendations to return a few hard coded values when the URI http://localhost:8080/movies
is accessed. The HTTP GET request for the above URI will be mapped to a controller method which returns a JSON response.
Let's see how Spring Boot makes application development easy. The application is created using the following steps:
Using Spring Initializr
There are numerous ways of creating a Spring Boot application. The easiest way is using the web UI called Spring Initializr. Other approaches include using the Spring Boot command line interface (CLI) and the Spring Tools Suite (STS) IDE. The Spring Initializr offers a way to bootstrap a Spring Boot application by offering a set of options to choose from. These are called starter projects. Starter projects make it very easy to develop applications. Since we want to develop a simple REST service, we need the web starter. We will fill the form on start.spring.io with the following information:
Group:
io.datajek.springbootdemo
Artifact:
recommender-api
Click "Add Dependencies" and choose the "Spring Web" dependency from the web section. Click on the "Generate" button, and once the project is downloaded, unzip and import the project into your IDE. ...