Member-only story
HTTP Methods for RESTful Services
The common HTTP methods! GET, POST, PUT, PATCH and DELETE
Prerequisites:
- None
Terminology
The methods:
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
Others:
Idempotent: An operation that produces the same results if executed multiple times
JSON: JavaScript Object Notation, a lightweight format for storing and transporting data
URI: Uniform Resource Identifier
The HTTP Verbs
POST
We can think of POST as a way to create new resources.
Creating
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.
On Success
We should expect a HTTP status of 201 to be returned, including a link to the newly created resource.
Idempotent?POST
is not idempotent, although making two identical POST
request is expected to result in two identical resources
Example
http://www.example.com/customers
GET
We think of GET
requests as a way to retrieve resource(s)
Read
We can read existing resources which are usually returned in JSON
format to the client
On Success
We should expect a HTTP status of 200 (OK) to be returned, with a representation of the request usually in JSON
format.
Idempotent?
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.