Http API Design

Source: Internet
Author: User

The Heroku team summarizes some of the HTTP API design guidelines based on Heroku platform APIs and their own in-house system practices, which are posted on github.

Address: Https://github.com/interagent/http-api-design

In view of too many companies to see the HTTP interface does not follow the standard specification to implement, recommended to do the service interface design and front-end students look.

Some of them are very important to draw out:

  • Return the correct status code

Do not always use 200! 201,202 It is very meaningful to correspond to different method. Error should return the correct status code, is the request parameter error please return 400, is the server internal error please return 500, the server pressure is too large to kill connection please return 503, for the behavior error instead of the permission problem do not use 401 and 403. These status codes themselves make sense, and do not need to create code or use extra attributes.

  • Use UTC time in ISO8601 format

Remember to use UTC and format uniformly, and really need to refer to Moment.js in each project to process the time? Time zone and format enough headache, moment.js is not omnipotent.

  • Give a structured error message

Error do not return to the state only, can give a certain error message in the case to return a unified structured error message in the body. This allows the client to make the correct processing, whether to wait for a retry or to stop the request from notifying the user.

Of course, there are a lot of them.

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.