Explain the difference between POST and PUT when creating a resource.
Last updated
Both can create a resource, but POST lets the server assign the URI and is non-idempotent, while PUT creates (or replaces) a resource at a client-specified URI and is idempotent.
POSTto a collection:POST /users: the server generates the ID and returns it (often with201 Createdand aLocationheader).Calling it twice makes two resources, so it is not idempotent.
PUTto a specific URI:PUT /users/42: the client chooses the identifier; the server creates it if absent or replaces it if present.Calling it twice with the same body leaves the same single resource, so it is idempotent.
Rule of thumb: use
POSTwhen the server owns ID generation,PUTwhen the client knows the target URI.
- https://www.sendowl.com/s/job-search
- https://www.ashokit.in/blog/top-microservices-interview-questions-and-answers
- https://www.resumeadapter.com/blog/full-stack-developer-resume-keywords
- https://meduzzen.com/hire/backend-developers/
- https://www.greatfrontend.com/blog/latest
- https://prepfully.com/interview-guides/hubspot-software-engineer
- https://www.getsmartresume.com/article/netflix-internship-new-grad-opportunities