Because REST uses the underlying HTTP protocol, each REST method is associated with one of the (5) specific HTTP commands or verbs listed below. As the listing shows, each verb generally maps to one of the command verbs found in SQL's Data Manipulation Language:
REST HTTP Verb
|
SQL equivalent
|
Use case
|
GET
|
SELECT
|
Query, retrieve data
|
POST
|
INSERT
|
Add new data
|
PUT
|
UPDATE
|
Change existing data, in the sense of changing a REST resource as a whole
|
DELETE
|
DELETE
|
Drop existing data
|
PATCH
|
UPDATE
|
Change existing data, in the sense of changing only a part of a REST resource
|
Example
A REST service offers the possibility to alter the information of a person.A user wants to change the address of a person with the PERSON_ID 154. The request URL is:
http://localhost:8090/myservice/myconnection/Person;PERSON_ID=154;
The user or software issuing the request must be instructed to specify the HTTP method PUT or PATCH depending on the type of change. If your update is a major update, and you want to replace or create the resource identified by PERSON_ID 154, you use PUT. If you have a minor change to the resource identified by PERSON_ID 154, you use PATCH. This method requires content in the body, which could look like this (if the Content Type is "text-xml"):
<PERSON PERSON_ID="154" ADDRESS="Carlton Street 4"/>
Or it could look like this, if the Content Type is "application/json":
{"PERSON_ID" : "154", "ADDRESS" : "Carlton Street 4"}
Changing the address is considered a minor change, so the most logical HTTP Verb to associate this functionality with is PATCH. If you are interested in an implementation example, please take a look at Example: a REST Service for manipulating data (UPDATE)
|