Fully resource-oriented, the API is represented in plural form
Path (Endpoint)
-
http://example.com/libraries //列出所有图书馆
-
http://example.com/books //列出所有图书
-
http://example.com/libraries/ID/books //列出某个图书馆的全部图书
-
http://example.com/libraries/ID/books/ID //列出某个图书馆的某本图书
- Filter criteria
-
http://example.com/books?library_id=ID //参数的存在允许API路径与URL参数有相同的含义
-
http://example.com/libraries/ID/books?book_type=biography&year=2010
- HTTP verbs
-
GET Remove Resources from server
-
POST creates a new resource to the server
-
PUT updates the resource to the server (the client provides complete resources to the server)
-
Patch updates the resource to the server (the client provides updated properties to the server)
-
Delete Deletes a resource
- Status code--Common HTTP status Code
-
200 server successfully returned to Web page
-
-
404 The requested Web page does not exist
-
503 Server is temporarily unavailable
-
-
500 Server Internal Error
- Error handling: If the return status code is 4xx, you should return an error message to the client, usually with the error as the key name, and the fault message as the key value.
-
{ error: "Invalid API key" }
REST API Design Specifications