Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- gcp
- 클라우드 컴퓨팅
- 카프카
- VPC
- JPA
- Spring Data JPA
- 스프링부트
- 로드밸런서
- Elasticsearch
- 오일러프로젝트
- 알고리즘
- Spring
- 쿠버네티스
- Kafka
- 백트래킹
- 스프링 부트
- springboot
- aws
- 월미도
- Apache Kafka
- 코드업
- 자료구조
- 인천여행
- 백준
- Docker
- 스프링
- 클라우드
- DFS
- 프로그래밍문제
- Spring Boot
Archives
- Today
- Total
GW LABS
스프링 부트 핵심 가이드 (3) - API를 작성하는 다양한 방법 본문
5.2 GET API
- 리소스 조회
- RequestMapping
- GetMapping
- PostMapping
- PutMapping
- DeleteMapping
- PathVariable
- RequestParam
@Tag(name = "GetController")
@RestController
@RequiredArgsConstructor
@RequestMapping("/five/v1/")
public class GetController {
private final FiveService fiveService;
@Operation(summary = "pathVariableExample")
@GetMapping("/person/{name}")
public ResponseEntity<Person> pathVariableExample(@Parameter(description = "이름 입력") @PathVariable String name) {
return ResponseEntity.status(HttpStatus.ACCEPTED).body(fiveService.getNamedPerson(name));
}
@Operation(summary = "requestParamExample")
@GetMapping("/person/request")
public ResponseEntity<Person> requestParamExample(@Parameter(description = "이름 입력") @RequestParam String name) {
return ResponseEntity.status(HttpStatus.OK).body(fiveService.getNamedPerson(name));
}
}
5.3 POST API
- 리소스 생성
- RequestBody
- DTO
@Tag(name = "PostController")
@RestController
@RequestMapping("/five/v1")
@RequiredArgsConstructor
public class PostController {
private final FiveService fiveService;
@Operation(description = "생성요청")
@PostMapping("/person")
public ResponseEntity<Person> requestBodyExample(@Parameter(description = "생성요청") @RequestBody Person person) {
return ResponseEntity.status(HttpStatus.ALREADY_REPORTED).body(person);
}
}
5.4 PUT API
- 리소스 업데이트
- RequestBody
- ResponseEntity
@Tag(name = "PutController")
@RestController
@RequestMapping("/five/v1")
@RequiredArgsConstructor
public class PutController {
private final FiveService fiveService;
@PutMapping("/person")
public ResponseEntity<Person> putExample(@Parameter(description = "변경할 사람 정보") @RequestBody Person person) {
return ResponseEntity.status(HttpStatus.ACCEPTED).body(fiveService.getSamplePerson());
}
}
5.5 DELETE API
- 리소스 삭제
- RequestParam/PathVariable
@Tag(name = "DeleteController")
@RestController
@RequestMapping("/five/v1")
@RequiredArgsConstructor
public class DeleteController {
private final FiveService fiveService;
@Operation(description = "삭제요청")
@DeleteMapping("/person")
public ResponseEntity<Person> deleteExample(@Parameter(description = "삭제 요청할 사람 정보") @RequestBody Person person) {
return ResponseEntity.status(HttpStatus.OK).body(fiveService.getSamplePerson());
}
}
5.6 Swagger
- 책에서 사용하는 springfox-swagger2는 더 이상 사용할 수 없다.(buggy)
- 대신 springdoc-openapi-ui를 사용한다.
5.7 Logback
- logback-spring.xml
'Book-Review > Programing' 카테고리의 다른 글
스프링 부트 핵심 가이드 (5) - 테스트 코드 작성하기 (0) | 2022.08.15 |
---|---|
스프링 부트 핵심 가이드 (4) - 데이터베이스 연동 (0) | 2022.08.13 |
스프링 부트 핵심 가이드 (2) - 개발에 앞서 알면 좋은 기초 지식 (0) | 2022.08.11 |
스프링 부트 핵심가이드 (1) - 스프링 부트란? (0) | 2022.08.11 |
스프링으로 하는 마이크로서비스 구축 리뷰 (2) - 스프링 부트 소개 (1) | 2022.04.29 |
Comments