The HTTP methods, which are used for RESTful Web Services, map neatly to the common SQL statements.
CRUD OPERATION | HTTP METHOD | SQL STATEMENT |
---|---|---|
Create | POST | INSERT |
Read | GET | SELECT |
Update | PUT | UPDATE |
Delete | DELETE | DELETE |
SELECT * FROM your_tablehttp
GET /your_tableURL
https://...context.../your_tableExample 1 : Get all arcgis server list
SQL : select * from rest_url URL : https://transparentgov.net:3200/restapi/rest_urlExample 2 : Get all socrata open data domain
SQL : select * from domain_list URL : https://transparentgov.net:3200/restapi/domain_list
SELECT * FROM your_table where type='xxx' order by 'yyy' aschttp
GET /your_tableURL
https://...context.../your_table?select=* &where=type%3D%27xxx%27 &orderby=yyy &asc_desc=asc where clause type='xxx' must be encoded as type%3D%27xxx%27Example 1 : Get all arcgis server list sort by name
SQL : select * from rest_url where type='folder' or type='hub' order by name asc URL : https://transparentgov.net:3200/restapi/rest_url?select=*&orderby=name&asc_desc=asc&where=type%3D'folder'%20or%20type%3D'hub'Example 2 : Get all socrata open data domain sort by organization
SQL : select * from domain_list order by organization asc URL : https://transparentgov.net:3200/restapi/domain_list?select=*&orderby=organization&asc_desc=asc
SELECT * FROM a, b, c where a.id=b.customerID ..... You can create a view for this complex sql as your_viewhttp
GET /your_viewURL
https://...context.../your_view?select=*
INSERT INTO your_table (column_name1, column_name2, column_name3) VALUES ("value1", "value2", "value3");http
POST /your_table { "column_name1": "value1", "column_name2": "value2", "column_name3": "value3" }URL
https://...context.../your_table?pin=123456789 must provide security pin for update, insert, delete, no pin required for select
UPDATE your_table SET id = 2, column_name1 = "value1", column_name2 = "value2", column_name3 = "value3" WHERE id = 2;http
PUT /your_table?where=id=2 { "id": 2, "column_name1": "value1", "column_name2": "value2", "column_name3": "value3" }URL
https://...context.../your_table? where=id%3D2 & pin=123456789 { "id": 2, "column_name1": "value1", "column_name2": "value2", "column_name3": "value3" } where clause id = 2 must be encoded as id%3D2
UPDATE your_table column_name3 = "value3" WHERE id = 2;http
PATCH /your_table?where=id=2 { "column_name3": "value3" }URL
https://...context.../your_table? where=id%3D2 & pin=123456789 { "column_name3": "value3" } where clause id = 2 must be encoded as id%3D2Note
The difference between PUT and PATCH is that PUT must update all fields to make it idempotent. This fancy word basically means that you must always get the same result no matter how many times it is executed. This is important in network traffic, because if you’re in doubt whether your request has been lost during transmission, you can just send it again without worrying about messing up the resource’s data.
DELETE * FROM your_table WHERE id = 2;http
DELETE /your_table?where=id=2URL
https://...context.../your_table? where=id%3D2 & pin=123456789 where id = 2 must be encoded as id%3D2