DEV Community

Discussion on: Why you should use standard HTTP methods when designing REST APIs

Collapse
 
ericrini profile image
Eric Rini

I usually think of PUT as a replace.

given an entity A
when I PUT entity B into A
then B will replace A
    and A will be gone forever
Enter fullscreen mode Exit fullscreen mode

A practical example is saving a new file B to the location of an existing file A.

Likewise, I think of PATCH as a merge.

given an entity A
when I PATCH entity B into A 
then A and B will merge to become C
    and C will replace A
    and A and B will be gone forever
Enter fullscreen mode Exit fullscreen mode

A practical example is writing a new field value B to a SQL record A. The resulting SQL record C contains fields from both A and B.

Collapse
 
suhas_chatekar profile image
Suhas Chatekar

Completely agree with you. That perfectly describes what PUT and PATCH should do.

I avoided using that terminology as I have seen that developers new REST style find it difficult to understand that. And then there is this.

Maybe, this is a topic for its own blog?