Elaborate version of the management RESTFul API

table of Contents

Version management interface to realize the significance of

The importance of API version management is self-evident, for designers and users of the API, the version management has a very important significance.
First, API design and implementation are concerned, we need to consider backwards compatibility, but with the development or change of business requirements often cause compatibility achieve very complex, so the introduction of API versioning will be able to solve this embarrassing. At this time, we can provide multiple versions of API, no need for backward compatibility brains.
Secondly, in terms of API for users, but also the flexibility to choose to use a different version API, without worrying about compatibility issues API.

How to implement version management interface

The API version management there are already many mature practices, such as: the version information in the URL, or placed in the HTTP header, URL parameters, or even can be placed in the message body (the version information in the HTTP header , the version information as a URL parameter or no essential difference in these three ways the message body). Manage different versions of different ways to achieve the degree of difficulty, each with advantages and disadvantages.

  • The version information in the URL though destroyed REST architectural style, but because of different versions and be able to reflect the changes brought about in the URL, more intuitive.
  • The square version information in the HTTP request header, URL parameters or even the message body, the benefits remain the same URL, but the API implementers need to parse parameters passed version of the call to different implementations.

Project combat

Use the version information in the URL manner in version management project based on Spring MVC (such as Spring Boot) in doing so is based on several considerations as follows:

  1. API changes reflected directly in the URL, intuitive and clear, do not parse version parameter.
  2. Corresponding to different versions of the URL may need to pass different parameters, so for API implementations are concerned is resolved Controller different methods, without regard to compatibility parse the request parameters, simple; and the design pattern may be implemented from embrace change.
  3. Spring MVC framework for the release of information in this way is reflected in the URL native support is better, you do not need to do other work adaptation.

[Reference]
https://segmentfault.com/a/1190000006165182 RESTful API versioning strategy
http://www.lexicalscope.com/blog/2012/03/12/how-are-rest-apis-versioned/ How are REST versioned APIs?
https://blog.csdn.net/hengyunabc/article/details/20506345 ways Web API version control
https://juejin.im/post/5a0bd3e3f265da431047eabf how to do Web API version control?

Guess you like

Origin www.cnblogs.com/nuccch/p/11267267.html