In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to design the interface in the computer, the article is very detailed, has a certain reference value, interested friends must read it!
There are many factors to consider when designing an interface, such as
Interface service positioning, interface security, interface scalability, interface stability, interface cross-domain, interface protocol rules, interface path rules, interface singleness principle, interface filter interface combination.
Many other factors, this article will briefly analyze these factors.
A normative recommendation 1. Principle of responsibility
When designing an interface, we must make clear the responsibility of the interface, that is, the type of interface, what business problems should be solved by the interface, etc.
two。 Principle of oneness
Under the condition that the responsibility of the interface is clear, try to make the interface single, that is, an interface only does one thing, not more than two. Many non-experienced interface designers always think that the more things the interface does, the better it is, which is a very serious misunderstanding.
3. Protocol specification
When designing the interface, it should be clear whether to use HTTP protocol, HTTPS protocol or FTP protocol, which should be determined according to the specific situation.
FTP protocol (File Transfer Protocol, referred to as FTP) is a set of standard file transfer protocols for transferring files, such as .txt, .csv, etc., general file transfer, using FTP protocol
HTTP protocol, suitable for business scenarios with low or no security requirements
HTTPS=HTTP+SSL for business scenarios with high security requirements
4. Path rule
Since api acquires a resource, try to use nouns rather than verbs in the URL
/ api/v1.0/pruduct/2019
/ api/v1.0/users/2019
5.http request mode
Basic access protocols for interfaces: get (acquisition), post (added), put (modified) and delete (deleted)
Get / users: list all users
Get / users/id: get users according to id
Post / user: new users
Put / user/id: update users according to their id
Delete / user/id: delete users according to their id
6. domain name
Generally speaking, domain names are divided into primary domain names and proprietary domain names. The primary domain name is suitable for services where api remains unchanged or has little change for a long time, and proprietary domain names are used to solve specific proprietary businesses.
Take Baidu as an example:
(1) Primary domain name: www.baidu.com
(2) products and services
Baidu Library: https://wenku.baidu.com/
Baidu knows: https://zhidao.baidu.com/
Baidu Information: https://zhidao.baidu.com/
(3) Market activities
Baidu public welfare: http://gongyi.baidu.com
Baidu logo: http://logo.baidu.com/
Baidu World: https://baiduworld.baidu.com
7. Cross-domain consideration
In the case of a clear domain name, we must consider whether the interface is cross-domain or not, as well as the technical means that should be adopted.
8.api version
For the url of the interface, add the version number http://api.demo.com/v{d}/, for example, where d represents the version number, such as v1.0 and v2.0
Example: get the product information of a version with product number 2019 and version number v1.0
/ api/v1.0/Pruducts/2019
9. Appropriate filtering of information
When there are a large number of records (such as SELECT * FROM TBName), filter the data by adding some conditions, such as TOP, paging, grouping, sorting and WHERE conditions, etc.
Here are some common parameters.
? limit=100: returns 100 pieces of data
? offset=101: returns from Article 101 data
? page=10: refers to page 10
Per_page=100: 100 pieces of data per page
? sortby=name: sort field
? order=desc: descending order
? group=groupName: grouping
? producy_type=1: filter criteria
10. Return data format
Returns the data format, which generally consists of three fields:
(1) failure situation (status code, error code and error description)
{"status": 0 status / status code 0-indicates failure, 1-indicates success "error_code": "2003", / / error code. Generally, "error_des": "authentication failure" / / error description is defined at design time, and generally defined at design time}
(2) success (identify id, data object, status code)
{"sid": "sh30190111", / / token id "users": {"id": "al201901111341", / / user id "name": "Alan_beijing", / / user name "addr": "user address"}, "status": 1ram / status code 0-indicates failure, 1-indicates success} 11. Safety principle
Consideration of interface exposure, consideration of interface concurrency, consideration of interface attack prevention, consideration of interface cross-domain, etc.
twelve。 Scalability principle
When designing the interface, fully consider the scalability of the interface.
13. Define api boundaries
Any api, in terms of permissions, can be summed up as anonymous api and non-anonymous api. The former does not require verification, and the latter requires verification.
14. Define api return codes
When designing api, it is necessary to determine the api return code, such as
1-the authorization expires
404mura-Resource not found
500mura-internal server error
600fu-account is locked
Two anti-normative suggestions
There is such a business scenario: an interface needs to return the result of a combination of multiple api interfaces. In similar business scenarios, the designed interface is anti-normative to a certain extent.
1.Requestdata: [{url:'api1',type:'get',data: {...}}, {url:'api2',type:'get',data: {...}},] 2.Responce {status:0, msg:'',data: [{status:1,msg:'',data: []}, {status:1,msg:'',data: {}}]} three instances
Suppose there is a business: an ERP system that needs to provide two interfaces, one is the user access interface (which requires authentication), and the other is the user registration interface (no authentication is required).
According to the suggestions in part I and part II of this article, we will design the interface to meet the business requirements.
(1) define uniform parameters
1. Define uniform input parameters
two。 Define uniform output parameters
3. Define uniform error codes
(2) define the category of interface authorization
The following is the definition of interface authorization categories
(3) user interface
1. User registration
2.Request
3.Responce
4.code example
Request: {"mobile": 13636595499, "verify_code": "987654", "pwd": "123456"} Responce: (1) error {"status": 0, "error_code": 1001, "error_desc": "Mobile verification code is invalid"} (2) succed {"sid": "sh301901141529", "uid": 1, "status": 1} (4) user login
1. Overview of login interface
2.Request
3.Responce
4.Code
Responce:1.error {"status": 0, "error_code": 1002, "error_desc": "password error"} 2.succeed {"sid": "sh301901141529", "user": {"id": 1, "username": "", age:0, gender:0}, "status": 1} all the contents of the article "how to design interfaces in a computer" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.