Interface style restful api style Ten specification

  • The interface uses a different method of operation of a similar function to control functions without the use of a plurality of views manner
  • api user to communicate with the recommended use https
  • url Specification
    • To distinguish between sub-domains (cross-domain prone to such problems)
      • Front-end domain name using www.fandx.com
      • Back-end domain name using api.fandx.com
    • url way to distinguish (very simple can be achieved)
      • Front-end www.fandx.com
      • Backend www.fandx.com/api
  • version
    • www.fandx.com/api/v1/
  • Interface name (a noun)
    • www.fandx.com/api/v1/ nouns
  • method form
    • get query
    • Add post
    • put updated resource server (complete resource provided by the client after change)
    • patch update resources (provided by the client to change the properties) in the server
    • delete Delete resources from the server
  • Filtering, by transmitting the voice parameters uploaded url search criteria
    • ? Limit = 10 Specifies the number of records returned
    • ? Offset = return to the starting position specified record of 10
    • ? Page =, and the number of records per page 2 & per_page = 100 Specifies the first few pages
    • ? Sortby = name & order = asc specify which properties to return results by sorting, and sort order
    • ? Animal_type_id = 1 specified filter criteria
  • status code
    • 200 success
    • 300 Redirect
    • 400 Client Error
      • 401 user does not have permission token
      • 403 authorized users, but access is prohibited
      • 404 access resources can not be found
    • 500 internal server error
  • The error returned as key recommendations error
  • Back to Results
    • get / collection returns a list of resources
    • get / collection / resource returns a single resource object
    • post / collection returns a resource object for the new generation
    • put / collection / resource returns the full resource object
    • patch / collection / resource modified partial return to the full resource object
    • delete / collection / resource returns an empty document

Guess you like

Origin www.cnblogs.com/fandx/p/12125026.html