Web API를 설계할 때 HTTP Method를 사용하여 최대한 RESTful한 코드를 작성해야 한다.
그 중 엔티티(Entity)를 수정하는 Method인 PUT 과 PATCH 의 차이에 대해 다뤄보겠다.
The PUT 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.
RFC 문서에 따르면 PUT은 저장도, 수정도 가능한 메서드이며 경우에 따라 다르게 동작한다
엔티티가 존재하는 경우
payload에 담긴 정보를 바탕으로 새로운 엔티티를 생성하여 기존에 존재하던 엔티티를 대체한다.
엔티티가 존재하지 않는 경우
payload에 담긴 정보를 바탕으로 새로운 엔티티를 생성하여 저장한다.
이처럼 PUT은 기본적으로 생성하고, 대체하는 방식으로 이뤄진다.
This specification defines the new HTTP/1.1 [RFC2616] method, PATCH, which is used to apply partial modifications to a resource.
RFC 문서에 따르면, PATCH는 부분적인 수정을 위해 사용되는 메서드 이다.