search

Home  >  Q&A  >  body text

angular.js - Are there any popular best practices for designing the JSON data format returned by the API interface?

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_u1582phpcn_u15822800 days ago636

reply all(4)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-15 17:07:02

    This kind
    http://swagger.io/

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-15 17:07:02

    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

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-15 17:07:02

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

    reply
    0
  • 为情所困

    为情所困2017-05-15 17:07:02

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

    reply
    0
  • Cancelreply