RESUful
- Protocol
https
- HTTP verbs
HTTP verbs |
SQL command |
meaning |
GET |
SELECT |
Retrieve the resource(s) from the server. |
POST |
CREATE |
Create a new resource on the server. |
PUT |
UPDATE |
Update the resource on the server (the client provides the changed full resource). |
PATCH |
UPDATE |
Update resources on the server (client provides changed properties). |
DELETE |
DELETE |
Delete the resource from the server. |
HEAD |
|
Get metadata for a resource. |
OPTIONS |
|
Get information about which properties of the resource can be changed by the client. |
3. Status Codes
status code |
significance |
HTTP verbs |
meaning |
200 |
OK |
GET |
The server successfully returns the data requested by the user, and the operation is idempotent. |
201 |
CREATED |
POST/PUT/PATCH |
The user creates or modifies data successfully. |
202 |
Accepted |
* |
Indicates that a request has entered the background queue (async task). |
204 |
NO CONTENT |
DELETE |
User deleted data successfully. |
400 |
INVALID REQUEST |
POST/PUT/PATCH |
There is an error in the request sent by the user, and the server does not create or modify data. The operation is idempotent. |
401 |
Unauthorized |
* |
Indicates that the user does not have permissions (token, username, wrong password). |
403 |
Forbidden |
* |
Indicates that the user is authorized (as opposed to a 401 error), but access is forbidden. |
404 |
NOT FOUND |
* |
The request issued by the user is for a record that does not exist, and the server does not perform the operation, which is idempotent. |
406 |
Not Acceptable |
GET |
The format requested by the user is not available (eg the user requested JSON format, but only XML format). |
410 |
Gone |
GET |
The resource requested by the user is permanently deleted and will no longer be available. |
422 |
Unprocesable entity |
POST/PUT/PATCH |
When creating an object, a validation error occurred. |
500 |
INTERNAL SERVER ERROR |
* |
A server error occurs, and the user will not be able to tell whether the request made was successful. |
4. Return the result
HTTP verbs |
HATE |
meaning |
GET |
/collection |
Returns a list (array) of resource objects |
GET |
/collection/resource |
Returns a single resource object |
POST |
/collection |
Returns the newly generated resource object |
PUT |
/collection/resource |
Returns the complete resource object |
PATCH |
/collection/resource |
Returns the complete resource object |
DELETE |
/collection/resource |
returns an empty document |
参考地址http://www.ruanyifeng.com/blog/2014/05/restful_api