What is the difference between PUT, POST and PATCH?

Here are the main differences everyone should know with your Http Verbs.

HTTP POST

Should be used when sending data to the server for newly created resources.

Example:-

POST /test/create HTTP/1.1
Host: jonbock.com
name1=value1&name2=value2

Response:-

  • 201 (Created)
  • 200 Ok
  • 204 No Content

Ensure that POST

  • Are not cached on the client or server side, each call will result in a attempt to create the resource
  • Requests have no restrictions on data length

 

 

HTTP PUT

HTTP PUTs should be idempotent when used to create/update a resource, this means that each call should result in the same result occurring. The main difference between PUT and POST is that POST could result in side effects when called multiple times.

Example:-

Response:-

  • 201 (Created)
  • 200 Ok
  • 204 No content

 

HTTP PATCH

HTTP PATCH is used to update partial entity, it is usually used to send one or more changes to the server to be applied.

Example:-

HTTP PATCH /users/1

[
     { “op”: “replace”, “path”: “/email”, “value”: “[email protected]” }
]

Response:-

  • 204 No content