|
| 1 | +[[webflux-versioning]] |
| 2 | += API Versioning |
| 3 | +:page-section-summary-toc: 1 |
| 4 | + |
| 5 | +[.small]#xref:web/webmvc-versioning.adoc[See equivalent in the Servlet stack]# |
| 6 | + |
| 7 | +Spring WebFlux supports API versioning. This section provides an overview of the support |
| 8 | +and underlying strategies. |
| 9 | + |
| 10 | +Please, see also related content in: |
| 11 | + |
| 12 | +- Use xref:web/webflux/controller/ann-requestmapping.adoc#webflux-ann-requestmapping-version[API Versions] |
| 13 | +to map requests to annotated controller methods |
| 14 | +- Configure API versioning in xref:web/webflux/config.adoc#webflux-config-api-version[WebFlux Config] |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +[[webflux-versioning-strategy]] |
| 19 | +== ApiVersionStrategy |
| 20 | +[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-strategy[See equivalent in the Servlet stack]# |
| 21 | + |
| 22 | +This strategy holds all application preferences about how to manage versioning. |
| 23 | +It delegates to xref:#webflux-versioning-resolver[ApiVersionResolver] to resolve versions |
| 24 | +from requests, and to xref:#webflux-versioning-parser[ApiVersionParser] to parse raw version |
| 25 | +values into `Comparable<?>`. It also helps to xref:#webflux-versioning-validation[validate] |
| 26 | +request versions. |
| 27 | + |
| 28 | +NOTE: `ApiVersionStrategy` helps to map requests to `@RequestMapping` controller methods, |
| 29 | +and is initialized by the WebFlux config. Typically, applications do not interact directly with it. |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +[[webflux-versioning-resolver]] |
| 35 | +== ApiVersionResolver |
| 36 | +[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-resolver[See equivalent in the Servlet stack]# |
| 37 | + |
| 38 | +This strategy resolves the API version from a request. The WebFlux config provides built-in |
| 39 | +options to resolve from a header, a request parameter, or from the URL path. |
| 40 | +You can also use a custom `ApiVersionResolver`. |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +[[webflux-versioning-parser]] |
| 46 | +== ApiVersionParser |
| 47 | +[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-parser[See equivalent in the Servlet stack]# |
| 48 | + |
| 49 | +This strategy helps to parse raw version values into `Comparable<?>`, which helps to |
| 50 | +compare, sort, and select versions. By default, the built-in `SemanticApiVersionParser` |
| 51 | +parses a version into `major`, `minor`, and `patch` integer values. Minor and patch |
| 52 | +values are set to 0 if not present. |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +[[webflux-versioning-validation]] |
| 58 | +== Validation |
| 59 | +[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-validation[See equivalent in the Servlet stack]# |
| 60 | + |
| 61 | +If a request version is not supported, `InvalidApiVersionException` is raised resulting |
| 62 | +in a 400 response. By default, the list of supported versions is initialized from declared |
| 63 | +versions in annotated controller mappings. You can add to that list, or set it explicitly |
| 64 | +to a fixed set of versions (i.e. ignoring declared ones) through the MVC config. |
| 65 | + |
| 66 | +By default, a version is required when API versioning is enabled, but you can turn that |
| 67 | +off in which case the highest available version is used. You can also specify a default |
| 68 | +version. `MissingApiVersionException` is raised resulting in a 400 response when a |
| 69 | +version is required but not present. |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +[[webflux-versioning-mapping]] |
| 75 | +== Request Mapping |
| 76 | +[.small]#xref:web/webmvc-versioning.adoc#mvc-versioning-mapping[See equivalent in the Servlet stack]# |
| 77 | + |
| 78 | +`ApiVersionStrategy` supports the mapping of requests to annotated controller methods. |
| 79 | +See xref:web/webflux/controller/ann-requestmapping.adoc#webflux-ann-requestmapping-version[API Versions] |
| 80 | +for more details. |
0 commit comments