Spring Boot REST API Full Tutorial
<p>This is a complete tutorial of building a REST api with Spring Boot with. You will learn how to :</p>
<ol>
<li>Create REST APIs</li>
<li>Add spring security with jwt authentication & authorization</li>
<li>Work with database</li>
<li>Add database migration with flyway</li>
</ol>
<p>The source code of this tutorial is published in git : <a href="https://github.com/farhantanvirtushar/spring-rest-demo" rel="noopener ugc nofollow" target="_blank"><strong>https://github.com/farhantanvirtushar/spring-rest-demo</strong></a></p>
<h1>Creating A Spring Boot REST API</h1>
<p>Create a spring boot application from <a href="https://start.spring.io/" rel="noopener ugc nofollow" target="_blank"><strong>Spring Initializr</strong></a> with Java version 17. Then add following dependency in <strong>pom.xml</strong> :</p>
<pre>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency></pre>
<p>Create a new package named controllers. Then create a new controller named <strong>HomeController.java</strong> inside our newly created controllers package. Write the following code inside HomeController.java :</p>
<pre>
package com.example.springrestdemo.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/rest/home")
public class HomeController {
@ResponseBody
@RequestMapping(value = "",method = RequestMethod.GET)
public String hello(){
return "hello world";
}
}</pre>
<p>We have created an api endpoint <strong>“/rest/home” </strong>for GET request. Now run the application through IDE or through command line with the following command</p>
<p><a href="https://medium.com/code-with-farhan/spring-boot-rest-api-full-tutorial-8e577050443b">Click Here</a></p>