Version control tips for API development

Source: Internet
Author: User

Version control tips for API development

Chszs, reprint need to indicate. Blog home:Http://blog.csdn.net/chszs

When designing and building APIs, versioning of the APIs is very important.

You must ensure that the new API does not cause damage to existing APIs.

First, and most importantly, you can put the version number in the URL of the API. This allows the major version updates to be put into the API. For example, when we call the Chuser Center API, we can use/API-V1 or/api-v2 in the URL to indicate which API version is being used. This is a very common practice.


In API version control, it is also important. You want the API to support minor version updates. The changes caused by minor version updates still affect the interface, so it is possible to affect the consumer of the current API, but they differ from the basic functionality of the main version of the URL and API, and the basic functionality of the URL and API is still the same. For example, in the Chuser Center API, the minor version of the modification is specified by the HTTP header that the client initiated the request at the time of the API call.

Chszs, reprint need to indicate. Blog home:Http://blog.csdn.net/chszs

The version element of the head looks like this:

Element-version:1

Another example of an API minor version update is if we want to modify the name of the JSON field for the response. Suppose we have an API call called Get/people, which returns the following JSON data:

{
"Firstn": "foo"
}

We decided to change the FIRSTN in the JSON field to FirstName. Obviously, this is only a minor change, so it's part of the API minor version update, without the revision of the master version and different URL signatures. So, we're going to create another get/people interface, and to call it, we need to add the HTTP header

Element-version:2

The following JSON data is then returned:


{
"FirstName": "foo"
}

In the Chuser Center API, when a new user is registered, we set this user's HTTP header to default to the latest elements-version version on Chuser Center. This ensures that new users always use the latest API services we provide so that no HTTP header elements are specified at each API call. Of course, you can also specify the version manually.

Version control tips for API development

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.