--Assumption that REST API is implemented in Spring Boot --Introduce swagger-ui to generate API documentation --Just add ʻio.springfox: springfox-boot-starter: 3.0.0` to gradle
--Create a new project by selecting Spring Web in Spring Initializr --Implemented REST API --Create src \ main \ java \ com \ example \ demo \ api \ DemoController.java with the following contents
package com.example.demo.api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@RequestMapping("/api/demo")
public class DemoController {
@GetMapping("/customers")
public String[] customers() {
return new String[] {
"AIUEO",
"Kakikukeko",
"SA Shi Su Se So"
};
}
@GetMapping("/customer/{id}")
public Map<String, String> customer(@PathVariable String id) {
return Map.of(
"id", id,
"name", "name",
"address", "Tokyo");
}
}
--Added to build.gradle
build.gradle
implementation "io.springfox:springfox-boot-starter:3.0.0"
--Application launch --Open http: // localhost: 8080 / swagger-ui / in your browser
Recommended Posts