REST API Design Specifications

Source: Internet
Author: User

  1. Fully resource-oriented, the API is represented in plural form

  2. Path (Endpoint)

    • http://example.com/libraries              //列出所有图书馆
    • http://example.com/books                  //列出所有图书
    • http://example.com/libraries/ID/books     //列出某个图书馆的全部图书
    • http://example.com/libraries/ID/books/ID  //列出某个图书馆的某本图书
  3. Filter criteria
    • http://example.com/books?library_id=ID    //参数的存在允许API路径与URL参数有相同的含义
    • http://example.com/libraries/ID/books?book_type=biography&year=2010  
  4. HTTP verbs
      • GET Remove Resources from server
      • POST creates a new resource to the server
      • PUT updates the resource to the server (the client provides complete resources to the server)
      • Patch updates the resource to the server (the client provides updated properties to the server)
      • Delete Deletes a resource
  5. Status code--Common HTTP status Code
      • 200 server successfully returned to Web page
      • 304 Not modified
      • 404 The requested Web page does not exist
      • 503 Server is temporarily unavailable
      • 504 Gateway Timeout
      • 500 Server Internal Error
  6. Error handling: If the return status code is 4xx, you should return an error message to the client, usually with the error as the key name, and the fault message as the key value.
    • { error: "Invalid API key" }

REST API Design Specifications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.