2025-05-09 23:37:23 +08:00
|
|
|
[[webflux-versioning]]
|
|
|
|
= API Versioning
|
|
|
|
:page-section-summary-toc: 1
|
|
|
|
|
|
|
|
[.small]#xref:web/webmvc-versioning.adoc[See equivalent in the Servlet stack]#
|
|
|
|
|
|
|
|
Spring WebFlux supports API versioning. This section provides an overview of the support
|
|
|
|
and underlying strategies.
|
|
|
|
|
|
|
|
Please, see also related content in:
|
|
|
|
|
|
|
|
- Use xref:web/webflux/controller/ann-requestmapping.adoc#webflux-ann-requestmapping-version[API Versions]
|
|
|
|
to map requests to annotated controller methods
|
|
|
|
- Configure API versioning in xref:web/webflux/config.adoc#webflux-config-api-version[WebFlux Config]
|
|
|
|
|
2025-05-14 20:00:29 +08:00
|
|
|
TIP: API versioning is also supported on the client side in `RestClient`, `WebClient`, and
|
|
|
|
xref:integration/rest-clients.adoc#rest-http-interface[HTTP Service] clients, as well as
|
|
|
|
for testing with `WebTestClient`.
|
|
|
|
|
|
|
|
|
2025-05-09 23:37:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
[[webflux-versioning-strategy]]
|
|
|
|
== ApiVersionStrategy
|
|
|
|
[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-strategy[See equivalent in the Servlet stack]#
|
|
|
|
|
|
|
|
This strategy holds all application preferences about how to manage versioning.
|
|
|
|
It delegates to xref:#webflux-versioning-resolver[ApiVersionResolver] to resolve versions
|
|
|
|
from requests, and to xref:#webflux-versioning-parser[ApiVersionParser] to parse raw version
|
|
|
|
values into `Comparable<?>`. It also helps to xref:#webflux-versioning-validation[validate]
|
|
|
|
request versions.
|
|
|
|
|
|
|
|
NOTE: `ApiVersionStrategy` helps to map requests to `@RequestMapping` controller methods,
|
|
|
|
and is initialized by the WebFlux config. Typically, applications do not interact directly with it.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[webflux-versioning-resolver]]
|
|
|
|
== ApiVersionResolver
|
|
|
|
[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-resolver[See equivalent in the Servlet stack]#
|
|
|
|
|
|
|
|
This strategy resolves the API version from a request. The WebFlux config provides built-in
|
|
|
|
options to resolve from a header, a request parameter, or from the URL path.
|
|
|
|
You can also use a custom `ApiVersionResolver`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[webflux-versioning-parser]]
|
|
|
|
== ApiVersionParser
|
|
|
|
[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-parser[See equivalent in the Servlet stack]#
|
|
|
|
|
|
|
|
This strategy helps to parse raw version values into `Comparable<?>`, which helps to
|
|
|
|
compare, sort, and select versions. By default, the built-in `SemanticApiVersionParser`
|
|
|
|
parses a version into `major`, `minor`, and `patch` integer values. Minor and patch
|
|
|
|
values are set to 0 if not present.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[webflux-versioning-validation]]
|
|
|
|
== Validation
|
|
|
|
[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-validation[See equivalent in the Servlet stack]#
|
|
|
|
|
|
|
|
If a request version is not supported, `InvalidApiVersionException` is raised resulting
|
|
|
|
in a 400 response. By default, the list of supported versions is initialized from declared
|
|
|
|
versions in annotated controller mappings. You can add to that list, or set it explicitly
|
|
|
|
to a fixed set of versions (i.e. ignoring declared ones) through the MVC config.
|
|
|
|
|
|
|
|
By default, a version is required when API versioning is enabled, but you can turn that
|
|
|
|
off in which case the highest available version is used. You can also specify a default
|
|
|
|
version. `MissingApiVersionException` is raised resulting in a 400 response when a
|
|
|
|
version is required but not present.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[webflux-versioning-mapping]]
|
|
|
|
== Request Mapping
|
|
|
|
[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-mapping[See equivalent in the Servlet stack]#
|
|
|
|
|
|
|
|
`ApiVersionStrategy` supports the mapping of requests to annotated controller methods.
|
|
|
|
See xref:web/webflux/controller/ann-requestmapping.adoc#webflux-ann-requestmapping-version[API Versions]
|
|
|
|
for more details.
|