The common HTTP methods! GET, POST, PUT, PATCH and DELETE
DELETE: delete a resource identified by a URI
GET: requests data from a specified endpoint
PATCH: used to modify resources
POST: sends data to a specified endpoint to create or update a resource
PUT: used to update resources
Idempotent: An operation that produces the same results if executed multiple times
URI: Uniform Resource Identifier
The HTTP Verbs
We can think of POST as a way to create new resources.
Typically the resources that are created are subordinate resources; that we
POST to the parent and the service associates the new resource to the parent.
We should expect a HTTP status of 201 to be returned, including a link to the newly created resource.
POST is not idempotent, although making two identical
POST request is expected to result in two identical resources
We think of
GET requests as a way to retrieve resource(s)
We can read existing resources which are usually returned in
JSON format to the client
We should expect a HTTP status of 200 (OK) to be returned, with a representation of the request usually in
Because we are reading resources, they should be the same every time. There should also be no risk of corruption since we are reading resources rather than creating or changing any.
We think of
PUT requests as a way to update resource(s)
When updating resources we can expect an existing resource to be replaced with an updated resource. If an update is run on a resource that does not currently exist
PUT creates the resource and returns 201 to represent a successful creation of the resource.
A successful update returns 200, but if the resource is created a 201 is returned. A body can be returned but is optional.
PUT can be a counter, which clearly identifies that a
PUT request may not be
idempotent, and it is advised that the documentation records if the request is
PATCH request modifies resources, and to do so only contains the changes to the resource (that is, the patch rather than a complete resource)
PATCH is superficially similar to
PUT, but does not consume as much bandwidth by sending a complete resource. The patch itself can be thought of as a set of instructions that update the existing resource using a patch language (JSON Patch is one such language)
A successful patch returns 200.
Patches update the resource, so we would not expect the request to be
idempotent unless care is taken to make it so (and equally prevent collisions between multiple patch requests).
DELETE removes a resource
DELETE removes a resource specified by a
A successful deletion returns 200.
By definition this is not
idempotent as calling a
DELETE multiple times can be expected to return a 404 NOT FOUND as
DELETE has already been called on the resource.
Match the HTTP Verbs to CRUD Operations
You’d be well advised to know something about HTTP methods during your software development career. You’d be surprised how many developers are confused between
PATCH (for example). This guide should give you some indication of the differences, and the responses you can expect from your client.
Hey! If you like it, why not hit me up on Twitter?
Extend your knowledge
You can read more about REST and CRUD through this link
The Twitter contact:
Any questions? You can get in touch with me HERE