Sobes.tech
Junior

What is the difference between PUT, POST, and PATCH methods?

sobes.tech AI

Answer from AI

  • PUT: Idempotent. Used for creating or fully updating a resource at the specified URL. If the resource exists, it will be replaced; if not, it will be created.
  • POST: Not idempotent. Used for sending data to create a new resource, add data to an existing resource, or perform an action. Each POST request can create a new resource or change the server state differently than the previous request.
  • PATCH: Not generally idempotent (though it can be idempotent under certain conditions). Used for partial updates to an existing resource. The request body contains a set of changes to be applied to the resource.
Method Idempotency Purpose Example Usage
PUT Yes Create/Full Update /users/123 (update user 123)
POST No Create resource, send data, perform action /users (create a new user)
PATCH Not always Partial update /users/123 (change only the email of user 123)