PUT/PATCH REST APIs - All you need to know about why and where to use Put vs Patch | Summary and Q&A

TL;DR
PUT and PATCH methods are used to update resources in a Rest API, with PUT allowing both creation and update, while PATCH is used for making specific changes to a resource.
Key Insights
- 🤼♂️ PUT and PATCH methods are used for updating resources in Rest API.
- ❓ PUT can be used for both creating and updating resources.
- 💱 PATCH is more efficient when only specific changes need to be made to a resource.
- ❓ PUT requests require sending the entire body of the resource in the request payload.
- 💱 PATCH requests only require sending the changes or differences in the request payload.
- 🛟 Servers may support or restrict the creation of resources using PUT.
- 💱 PUT and PATCH requests are idempotent and do not change the server state when sent multiple times.
Transcript
hello and welcome to sudo boot in case you guys don't know me and you're new to the channel my name is yokita sharma and i work as a software engineer for curry this is a video in the series of rest api videos and today we are going to discuss put and patch methods so let's get started up until now we have seen how to use post methods to create a r... Read More
Questions & Answers
Q: What is the difference between PUT and PATCH methods?
PUT is used for replacing the whole body of a resource, while PATCH is used for making specific changes or updates to a resource without replacing the entire body.
Q: Can PUT be used for creating a resource?
Yes, if the client has access to the resource's ID and the server supports it, PUT can be used to create a resource by sending the ID and the resource attributes in the request body.
Q: What happens when a PUT request is sent for a non-existent resource?
If the server supports the creation of resources using PUT, it will create the resource if it does not exist based on the ID sent in the request body.
Q: How is PATCH different from PUT?
PATCH is used for making specific changes to a resource, whereas PUT replaces the entire body of the resource. PATCH is more efficient when only a few attributes need to be updated.
Q: What is the difference between PUT and PATCH methods?
PUT is used for replacing the whole body of a resource, while PATCH is used for making specific changes or updates to a resource without replacing the entire body.
More Insights
-
PUT and PATCH methods are used for updating resources in Rest API.
-
PUT can be used for both creating and updating resources.
-
PATCH is more efficient when only specific changes need to be made to a resource.
-
PUT requests require sending the entire body of the resource in the request payload.
-
PATCH requests only require sending the changes or differences in the request payload.
-
Servers may support or restrict the creation of resources using PUT.
-
PUT and PATCH requests are idempotent and do not change the server state when sent multiple times.
-
POST method is used for creating resources, while PUT and PATCH are for updating existing resources.
Summary & Key Takeaways
-
PUT and PATCH methods are used for updating resources in Rest API.
-
PUT can be used for both creating and updating resources, depending on the existence of the resource.
-
PATCH is used for making specific changes to a resource without replacing the whole body.