When to use HTTP PUT vs PATCH? How PUT and PATCH methods work in HTTP explained.
π£π¨π§ π π²ππ΅πΌπ±:
π’ 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.