Back to all questions

What is the difference between PUT and PATCH?

Devs Hive

Devs Hive

Seen on interview: 2 users

Most likely, you will hear this question in a conversation about REST API design. It's important to understand that both methods are used to update a resource, but they differ in semantics.

How the resource is updated

PUT replaces the entire resource with a new representation. Put simply, it expects you to send all the fields that describe the resource, including those that don't need to be updated. PATCH, in turn, expects you to send only the fields that need to be updated.

Idempotency

According to HTTP semantics, PUT is an idempotent method. If you send it 10 times with the same body, the result is the same as if you had sent it once. PATCH is not necessarily idempotent, and it all depends on the implementation.

Seen on interview?

Comments (0)

Sign in to leave a comment

No comments yet. Be the first!