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.
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...