When to use HTTP PUT vs PATCH? How PUT and PATCH methods work in HTTP explained.

Rabib Galib
1 min readOct 3, 2024

--

HTTP PUT vs PATCH comparison

𝗣𝗨𝗧 π— π—²π˜π—΅π—Όπ—±:

🟒 The PUT method is used to update an existing resource or create a new one if it doesn’t exist.

πŸ” It’s idempotent, meaning the same request can be made multiple times with the same outcome.

πŸ“ When using PUT, you must provide the entire resource. If any attributes are left out, they are removed or reset.

🍦 For example, using PUT to update an ice cream object means replacing everything β€” the scoop, cone, and toppings.

𝗣𝗔𝗧𝗖𝗛 π— π—²π˜π—΅π—Όπ—±:

🟑 The PATCH method is for making partial updates or tweaks to a resource, not replacing it entirely.

⚠️ It’s not guaranteed to be idempotent, but it can be implemented that way.

✏️ With PATCH, you only send the specific changes you want, and attributes not mentioned remain unchanged.

🍨 For example, using PATCH to update just the scoop of the ice cream keeps the cone and toppings the same.

Happy coding! Have fun πŸ”₯ πŸ’ͺ. Find me on Github, LinkedIn.

--

--

Rabib Galib
Rabib Galib

Written by Rabib Galib

Senior Software Engineer, Masters in Computer Science & Engineering, PHP, Python, Chatbot Expert, AI Research

No responses yet