PUT : which is used to apply partial modifications to a resource
PATCH : method requests that the state of the target resource be created or replaced with the state defined by the representation enclosed in the request message payload
PUT의 경우 일부분의 값만을 보낼 경우 나머지 값을 default값으로 변경되며
PATCH는 변경된 값만을 반영시키며 나머지 값 같은 경우 유지되는것을 알 수 있다.
PUT 방식의 경우 아래와 같이 USER의 나이를 15살로 변경시 name에 대한 입력값이 없으므로 null값이 들어가게 된다.
PUT /users/1
{
"age": 15
}
HTTP/1.1 200 OK
{
"name": null,
"age": 15
}
하지만 PATCH의 경우 age의 값만을 입력했으나 name의 값은 유지되는 것을 볼 수 있다.
PATCH /users/1
{
"age": 15
}
HTTP/1.1 200 OK
{
"name": "gildong",
"age": 15
}
출처: https://devuna.tistory.com/77 [튜나 개발일기:티스토리]
'CS' 카테고리의 다른 글
면접 질문 (0) | 2022.09.05 |
---|---|
면접 질문 (0) | 2022.09.02 |
ORM, JPA, Spring Data JPA (1) | 2022.09.01 |
Controller, Service, Repository (0) | 2022.09.01 |
면접 질문 (0) | 2022.08.31 |