Source Address: http://fann.im/blog/2013/07/15/best-practices-for-restful-api/
do server development, inevitably have external interface, just see Best practices for designing a pragmatic RESTful API, simply excerpt to make a note.
- API is to face the developer's UI, so be friendly to the developer, can be easily accessed in the browser input.
- Comply with WEB standards as much as possible.
- Use RESTful URLs. The URL identifies the resource, HTTP Method (get/post/put/delete) Operation controls the resource, where get gets, POST new, PUT update, delete delete, and a PATCH section update.
- URLs identify resources in complex form.
- URL Resource as an atomic operation.
- documentation, and with appropriate examples, it is best to provide examples of direct browser +curl.
- Once the API is determined it is not easy to modify, update and delete to have the corresponding document description.
- The API has to be versioned and displayed directly in the URL, for example
/api/1/xyz .
- URLs can keep up with conditional filtering control parameters, such as
/tickets?state=open .
- Wrap a common set of conditions into a URL resource, for example
/tickets/recently_closed .
- The URL can contain a list of returned fields, returning only the contents of the specified field, such as
/tickets?fields=id,subject
- Only the JSON format, and then there is no need to indicate the format suffix in the URL.
- The URL is named in Serpentine (underlined form), for example
user_timeline .
- The API returns the Content-type to be set and the result is compressed with Gzip.
- RESTful GET is read only and does not allow data to be modified.
- API requests are limited in number of times, similar to Twitter rate limiting
- If necessary, use OAuth 2 authentication.
- The API header information contains cache information such as ETAG.
- Useful error message: Unique error code + error description information, with corresponding document.
- Take advantage of HTTP status code, such as 200/201/204/304/401/403/404/405.
IOS 8: "Go" restful programming best practices