Difference between Put and Patch

I know it’s a silly question, but I am finding a hard time understanding what the difference between Put and Patch is.

I hope somebody can share some light on this.

Thanks

You may be having a hard time finding the difference because many APIs don’t follow the strict definitions for them.

In short, let’s say you have a User entity that has fields for the username, password, and email. In your database/storage you have a entry for jdoe, My-Awesome#passWord946, jdoe@example.com.

If you send a PUT request, you’re expected to essentially be replacing all of the data. So you would send all of those fields, and all of the fields would be replaced with the data you sent. If you didn’t send one of the fields, say email, then it is assumed you want that data to be blank. (Caution.)

For a PATCH request, you just send the changed data for the entity. So if you wanted to update the email field, that is the only field you would send with the request, and that is the only field that would be replaced.

But as I said above, I’ve seen APIs that don’t follow this, and do unexpected things, so always best to read the docs for the API you are using.

1 Like

Thank you ! This makes alot of sense to me!