2023. 3. 12. 19:40ใ๐พBackEnd/๐ฑ Spring
๊ธ์ ์์ฑํ ์ด์
status์ฝ๋๋ฅผ ํ์ตํ๊ณ ์ฑ๊ณตํ๋ฉด ๋ฌด์กฐ๊ฑด OK(200) ๋ผ๋ ๊ณต์์ด ์์๋ค. ํ์ง๋ง ์ฝ๋ ๋ฆฌ๋ทฐ๋ฅผ ๋ฐ์ผ๋ฉด์ ์์ ํ ์๋ชป ์ดํดํ ๋ถ๋ถ์ด ์์ด ์ดํ์ ๋ณต๊ธฐ๋ฅผ ํ๊ธฐ ์ํด ์์ฑํ๋ค.
https://www.rfc-editor.org/rfc/rfc2616#section-9.7
RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1
www.rfc-editor.org
๊ธฐ์กด์ ํผ๋๋ฐฑ์ ๋ฐ์๋ ์ฝ๋๋ฅผ ์ดํด๋ณด์
@DeleteMapping("{id}")
@ResponseStatus(HttpStatus.OK)
public void delete(@PathVariable Long id){
this.userService.delete(id);
}
๋ด๊ฐ ์ด ์ฝ๋๋ฅผ ๊ตฌํ์ ํ๋ฉด์ ์๊ฐํ ๋ฐฉ์์ ์ญ์ ๊ฐ ์ฒ๋ฆฌ๋๋ฉด ์ฑ๊ณต์ ์๋ฏธํ๋ OK(200)๋ฅผ ์์ฑํ๋ค.
์์ธ์ ๋ํ ๋ถ๋ถ์ ControllerAdvice๋ฅผ ํตํ์ฌ ๋ฐ๋ก ์ฒ๋ฆฌํ๊ฒ ๋ง๋ค์๋ค.
mockMvc.perform(delete("/user/1")
.contentType(APPLICATION_JSON))
.andExpect(status().isOk())
ํ ์คํธ ์ฝ๋๋ฅผ ์์ฑ์ ํ์ฌ ํ ์คํธ๋ฅผ ํ์ฌ given()์ ํตํด ์์ฑ๋ ์ ์ ๋ฅผ delete๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์ฒ๋ฆฌ๊ฐ ๋์๋ค.
ํ์ง๋ง ์ด ๋ถ๋ถ์์ ์๋ชป๋ ๋ถ๋ถ์ ์์ ๋ฌธ์๋ฅผ ๋ณด๋ฉด ์๋ตํ๋ ๋ฐ์ดํฐ๊ฐ ์์ ๋๋ 204๋ก ์๋ตํ๋ผ๊ณ ์ฐ์ฌ์๋ค.
A successful response SHOULD be 200 (OK) if the response includes an
entity describing the status, 202 (Accepted) if the action has not
yet been enacted, or 204 (No Content) if the action has been enacted
but the response does not include an entity.
'๐พBackEnd > ๐ฑ Spring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ํธํ Bcrypt์ ๋ํ ์ฌ์ธต ๋ถ์ (2) | 2023.03.24 |
---|---|
[ Object Mapper] Dozer์ ๋ํด์ ๋ค์ด๋ ๋ดค๋? (0) | 2023.03.14 |
[ Jackson ] Jackson mock ํ ์คํธ ์ญ์ง๋ ฌํ ์ค๋ฅ (0) | 2023.03.11 |
Spring Boot Test H2 In Memory ์ค์ ํ๊ธฐ (0) | 2023.02.28 |
[SpringBoot] Slack์ผ๋ก ์๋ฆผ ๋ณด๋ด๊ธฐ (0) | 2023.02.15 |