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 | 29 | 
| 30 | 
													Tags
													
											
												
												- 스프링부트
 - 클라우드 컴퓨팅
 - JPA
 - 코드업
 - Apache Kafka
 - 스프링
 - 쿠버네티스
 - Spring Data JPA
 - Spring Boot
 - 로드밸런서
 - aws
 - 클라우드
 - Elasticsearch
 - 머신러닝
 - VPC
 - 오일러프로젝트
 - 개발
 - Docker
 - DFS
 - Spring
 - 백트래킹
 - 프로그래밍문제
 - 자료구조
 - Kafka
 - 카프카
 - 백준
 - springboot
 - 스프링 부트
 - 알고리즘
 - gcp
 
													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