restful-api Interface Design Specification describes

       First of all, we have to know what is restful-api, it produces what the background is, what role is, so in order better to learn and master this knowledge to us.

What is restful-api:

        EST, namely Representational State Transfer acronym. Directly translated means "the state transformed the presentation layer."
         It is the API design an Internet application: URL locate resources with HTTP verbs (GET, POST, DELETE, DETC, etc.) description of the operation.

Background and effect:

       In recent years the development of mobile Internet, an endless stream of front-end devices (phones, tablets, desktop computers, other equipment ...), front-end and back-end when developers need to interact during development and other tests, and that question is, in this interaction and testing how can we agree on the links, facilitate testing it? Therefore, in order to facilitate developers to test and improve development efficiency, therefore, there must be a unified mechanism to regulate, then RESTful born, and restful-api design specifications recognized by most programmers, it can be through a unified interface for the Web , iOS and Android provide services.

       I believe we read the contents of the above should have a certain knowledge and understanding of restful-api, then the next specific about the design specifications restful-api.

Specific design specifications:

1. API should try to be deployed under the private domain name

http://api.douban.com/v2/user/1000001?apikey=XXX

2. API version number should be put into URL

http://api.douban.com/v2/user/1000001?apikey=XXX

3. In a RESTful architecture, each URL represents a resource (resource), so 网址中不能有动词,只能有名词, and used 名词往往与数据库的表格名对应. In general, the table in the database are the same kinds of records "collection" (collection), so the API should also use plural nouns.

http://api.douban.com/v2/ book/: the above mentioned id (get book information)
http://api.douban.com/v2/ movie/ Subject /: the above mentioned id (movie entry information)
HTTP: //api.douban. COM / v2 / music/: the above mentioned id (get music information)
http://api.douban.com/v2/ event/: the above mentioned id (city acquired activities)

4. For the particular type of operation of the resource, the request mode, represented by the HTTP verbs. Common HTTP verbs have the following four (corresponding 增/删/改/查).

GET select( ): Remove the resource from the server (one or more).
eg. to obtain book information GEThttp://api.douban.com/v2/book/:id

POST create( ): Create a new resource on the server.
eg. a user's favorite book POSThttp://api.douban.com/v2/book/:id/collection

PUT ( update): (provide full resource after changing client) in the server updates the resource.
eg. the user modifies a book collection of the PUThttp://api.douban.com/v2/book/:id/collection

DELETE delete( ): delete the resource from the server.
eg. a user deletes an article notes DELETEhttp://api.douban.com/v2/book/annotation/:id

5. If a large number of records, the server can not all be returned to the user thereof. API should提供参数,过滤返回结果

?limit=10:Specifies the number of records returned
eg. Get Book information GEThttp://api.douban.com/v2/book/:id?limit=10

6. The server returned to the user状态码和提示信息

Each status code represents a different meaning, just as the code
2系represents the normal return
4系on behalf of the abnormal data
5系on behalf of the server to

Interface Security:
1.API authentication should use OAuth 2.0 framework.
2. The technical team own rules of engagement

Two additional parameters time, token
timefor the timestamp for determining whether an interface request timeout
tokenfor the timestamp string encryption, encryption rule only you know your own technical team

Published 17 original articles · won praise 1 · views 889

Guess you like

Origin blog.csdn.net/weixin_43914604/article/details/99695286