Supported versions with API versioning using the Spring framework

When enabling API versioning using Spring Framework 7 or later, in addition to defining the default version for endpoints that do not have a version defined, you can also define a list of versions supported by your API by using the addSupportedVersions() method when configuring API versioning as follows:

When using this addSupportedVersions() method, in addition to the versions that have been specifically defined for some endpoints, our API will also support the versions declared in the addSupportedVersions() method.

The versions defined in the addSupportedVersions() method will be automatically assigned to endpoints that do not define a version or endpoints that are defined with a baseline version using the “+” sign at the end of the version value, as follows:

Versions supported by my API, greater than this baseline version, will be handled by the hello1_2_0() method!

For my example above, the default version will be 1.0.0, supported versions are 5.0.0 and 1.0.2, specific versions are 1.1.0 and 1.2.0. My API will be able to handle the following versions for the “/hello” endpoint: 1.0.0, 1.0.2, 1.1.0, 1.2.0 and 5.0.0.

In ascending order of version, versions 1.0.0 and 1.0.2 will be handled by the hello() method! If you request with version 1.0.0 and 1.0.2, you will see the result as below:

and:

Version 1.1.0 will be handled by the hello_1_1_0() method:

And version 1.2.0, 5.0.0 will be handled by hello1_2_0() method:

If I remove support version 5.0.0 above:

then request the “/hello” endpoint again with version 5.0.0, you will see that our API no longer supports version 5.0.0:

Add Comment