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