General principles of REST API design

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.