https://devlog-wjdrbs96.tistory.com/182
[Spring Boot] ResponseEntity란 무엇인가?
먼저 REST API가 무엇인지는 아래 블로그를 먼저 잘 읽어보자. https://meetup.toast.com/posts/92 REST API 제대로 알고 사용하기 : TOAST Meetup REST API 제대로 알고 사용하기 meetup.toast.com 1. ResponseEn..
devlog-wjdrbs96.tistory.com
https://a1010100z.tistory.com/106
[Spring] ResponseEntity는 왜 쓰는 것이며 어떻게 쓰는걸까?
기존 내 개인 프로젝트 코드의 RestController 반환값은 모두 Object 타입이었다. 하지만, 일반적인 API는 반환하는 리소스에 Value만 있지 않다는 것을 모두 알고 있을 것이다. 당장 생각나는 것으로는
a1010100z.tistory.com
참고자료
ResponseEntity
- HTTP 정보들을 담아 전달하여 데이터(body), headers, Http status를 제어할 수 있는 클래스이다.
- HttpEntity(HTTP 요청 또는 응답에 해당하는 HttpHeader와 HttpBody를 포함하는 클래스) 클래스를 상속받아 구현한 클래스.(RequestEntity, ResponseEntity)
위의 코드는 생성자에 따라 body(문자열 부분), HttpStatus(HttpStatus.CREATED -> 201)에 대하여 파라미터를 넘겨주고 있다.
성공 시 "Created successfully" 문자열과 응답코드 201을 리턴한다.
'Back-end > Spring Boot' 카테고리의 다른 글
@RequestBody와 @ResponseBody (0) | 2021.10.07 |
---|---|
@RequestParam, @PathVariable, @RequestBody (0) | 2021.10.07 |
Spring Boot - REST API - 학습필요 (0) | 2021.10.07 |
Spring Boot 특징 (0) | 2021.10.06 |