angular.js - Are there any popular best practices for designing the JSON data format returned by the API interface?
phpcn_u1582
phpcn_u1582 2017-05-15 17:05:02
0
4
600

Recently, our company developed a project. PC side, mobile APP side, and mobile web side. Are there any popular best practices for designing the JSON data format returned by the API interface?

Currently I have found the following versions

Version 1: Successfully executed: head Status Code:2XX

json {"id":51,"age":58,"name":"lifei"}

Failed execution head Status Code:4XX-5XX {"message":"xxxxxx error","errors:{}}

Version 2: Successful and failed execution head Status Code:2xx

json {"code":"0","message:"information","data":{}}

Version 3: Successfully executed: head Status Code:2XX

json {"id":51,"age":58,"name":"lifei"}

Failed execution head Status Code:4XX-5XX {"code":10001, "message":"xxxxxx error","errors:{}}

If there are different types of errors in the business, for example, if I want to withdraw cash, there may be errors such as the bank card is not bound, the account book is not uploaded, the ID card is not uploaded, the mobile phone number is not bound, the address is not filled in, there is no balance, etc. wait.

phpcn_u1582
phpcn_u1582

reply all(4)
phpcn_u1582

This kind
http://swagger.io/

巴扎黑

http://jsonapi.org/

https://github.com/interagent...

This kind of specification is relatively complicated, but once you learn it, you will use it for life, and both the front-end and back-end can be easily reused

The advantage of defining your own specifications is that it is simple, but many details may not be considered during design, making modifications very troublesome

巴扎黑

https://github.com/ShuyunXIAN...

为情所困

JSON RPC 2.0
http://www.jsonrpc.org/specif...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template