This article is referenced from: http://www.ruanyifeng.com/blog/2014/05/restful_api.html
Server-side:
1. JSON form:
Request method |
Meaning |
API recommended Format (URL) v1-version number, |
Successful return value |
Failure Code (typical) |
Note |
PUT |
Modifying data requests (The client provides the full resource after the change) |
/v1/collection/id |
Complete object information (in JSON format) |
201 (Updated) 403 (Forbidden) (Servererror) |
|
POST |
Create a data request |
/v1/collection/id |
Newly created complete object information (in JSON format) |
201 (Created) 403 (Forbidden) (Servererror) |
|
DELETE |
Delete Data request |
/v1/collection/id |
Empty document |
403 (Forbidden) (Servererror) |
|
GET |
Read Data request |
/v1/collection/id Or /v1/collection/?limit=n?offset=10?page=2&per_page=100?sortby=name&order=asc?animal_type_id=1 |
A single Resource object Or List of resource objects (array) |
(OK) 404 (NotFound) 410 (Gone) |
|
PATCH |
Modifying data requests (The client provides changed properties) |
/v1/collection/id |
Complete object information (in JSON format) |
201 (Updated) 403 (Forbidden) (Servererror) |
|
The following comparison is less used |
HEAD |
Get metadata for a resource |
|
|
|
|
OPTIONS |
Get information, The client can modify the property set. |
|
|
|
|
|
|
|
|
|
|
Whether successful or unsuccessful, it is best to attach a link field, which is used to annotate the relevant API, prompting the user what to do next, as follows:
{"link": { "rel": "collection Https://www.example.com/zoos",//This API is related to the current URL "href": "https:// Api.example.com/zoos ",//api address " title ":" List of Zoos ",//api title " type ": " application/vnd.yourformat+ JSON "//API return value type}}
Add:
The API communicates with the user protocol, always using the HTTPS protocol.
The API's identity authentication should use the OAuth 2.0 framework.
General principles of REST API design