Skip to content

Commit 26d413c

Browse files
committed
Update router function docs for API versioning
Closes gh-35113
1 parent 701e034 commit 26d413c

File tree

6 files changed

+111
-11
lines changed

6 files changed

+111
-11
lines changed

framework-docs/modules/ROOT/pages/web/webflux-functional.adoc

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,10 @@ parameter, though which additional constraints can be expressed.
585585
=== Predicates
586586

587587
You can write your own `RequestPredicate`, but the `RequestPredicates` utility class
588-
offers commonly used implementations, based on the request path, HTTP method, content-type,
589-
and so on.
590-
The following example uses a request predicate to create a constraint based on the `Accept`
591-
header:
588+
offers built-in options for common needs for matching based on the HTTP method, request
589+
path, headers, xref:#api-version[API version], and more.
590+
591+
The following example uses an `Accept` header, request predicate:
592592

593593
[tabs]
594594
======
@@ -783,6 +783,51 @@ Kotlin::
783783
======
784784

785785

786+
787+
[[api-version]]
788+
=== API Version
789+
790+
Router functions support matching by API version.
791+
792+
First, enable API versioning in the
793+
xref:web/webflux/config.adoc#webflux-config-api-version[WebFlux Config], and then you can
794+
use the `version` xref:#webflux-fn-predicates[predicate] as follows:
795+
796+
[tabs]
797+
======
798+
Java::
799+
+
800+
[source,java,indent=0,subs="verbatim,quotes"]
801+
----
802+
RouterFunction<ServerResponse> route = RouterFunctions.route()
803+
.GET("/hello-world", version("1.2"),
804+
request -> ServerResponse.ok().body("Hello World")).build();
805+
----
806+
807+
Kotlin::
808+
+
809+
[source,kotlin,indent=0,subs="verbatim,quotes"]
810+
----
811+
val route = coRouter {
812+
GET("/hello-world", version("1.2")) {
813+
ServerResponse.ok().bodyValueAndAwait("Hello World")
814+
}
815+
}
816+
----
817+
======
818+
819+
The `version` predicate can be:
820+
821+
- Fixed version ("1.2") -- matches the given version only
822+
- Baseline version ("1.2+") -- matches the given version and above, up to the highest
823+
xref:web/webmvc/mvc-config/api-version.adoc[supported version].
824+
825+
See xref:web/webflux-versioning.adoc[API Versioning] for more details on underlying
826+
infrastructure and support for API Versioning.
827+
828+
829+
830+
786831
[[webflux-fn-serving-resources]]
787832
== Serving Resources
788833

framework-docs/modules/ROOT/pages/web/webflux-versioning.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Please, see also related content in:
1313
in the WebFlux Config
1414
- xref:web/webflux/controller/ann-requestmapping.adoc#webflux-ann-requestmapping-version[Map requests]
1515
to annotated controller methods with an API version
16+
- xref:web/webflux-functional.adoc#api-version[Route requests]
17+
to functional endpoints with an API version
1618

1719
Client support for API versioning is available also in `RestClient`, `WebClient`, and
1820
xref:integration/rest-clients.adoc#rest-http-interface[HTTP Service] clients, as well as

framework-docs/modules/ROOT/pages/web/webflux/controller/ann-requestmapping.adoc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,12 @@ superseded by (4), which allows only a strict match, and therefore does not matc
483483
In this scenario, a `NotAcceptableApiVersionException` results in a 400 response.
484484

485485
NOTE: The above assumes the request version is a
486-
xref:web/webmvc/mvc-config/api-version.adoc["supported" version], or otherwise it
487-
would fail xref:web/webflux-versioning.adoc#webflux-versioning-validation[Validation].
486+
xref:web/webflux/config.adoc#webflux-config-api-version["supported" version],
487+
or otherwise it would fail.
488+
489+
See xref:web/webflux-versioning.adoc[API Versioning] for more details on underlying
490+
infrastructure and support for API Versioning.
491+
488492

489493

490494

framework-docs/modules/ROOT/pages/web/webmvc-functional.adoc

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,10 @@ parameter, through which additional constraints can be expressed.
555555
=== Predicates
556556

557557
You can write your own `RequestPredicate`, but the `RequestPredicates` utility class
558-
offers commonly used implementations, based on the request path, HTTP method, content-type,
559-
and so on.
560-
The following example uses a request predicate to create a constraint based on the `Accept`
561-
header:
558+
offers built-in options for common needs for matching based on the HTTP method, request
559+
path, headers, xref:#api-version[API version], and more.
560+
561+
The following example uses an `Accept` header, request predicate:
562562

563563
[tabs]
564564
======
@@ -761,6 +761,51 @@ Kotlin::
761761
======
762762

763763

764+
765+
[[api-version]]
766+
=== API Version
767+
768+
Router functions support matching by API version.
769+
770+
First, enable API versioning in the
771+
xref:web/webmvc/mvc-config/api-version.adoc[MVC Config], and then you can use the
772+
`version` xref:#webmvc-fn-predicates[predicate] as follows:
773+
774+
[tabs]
775+
======
776+
Java::
777+
+
778+
[source,java,indent=0,subs="verbatim,quotes"]
779+
----
780+
RouterFunction<ServerResponse> route = RouterFunctions.route()
781+
.GET("/hello-world", version("1.2"),
782+
request -> ServerResponse.ok().body("Hello World")).build();
783+
----
784+
785+
Kotlin::
786+
+
787+
[source,kotlin,indent=0,subs="verbatim,quotes"]
788+
----
789+
val route = router {
790+
GET("/hello-world", version("1.2")) {
791+
ServerResponse.ok().body("Hello World")
792+
}
793+
}
794+
----
795+
======
796+
797+
The `version` predicate can be:
798+
799+
- Fixed version ("1.2") -- matches the given version only
800+
- Baseline version ("1.2+") -- matches the given version and above, up to the highest
801+
xref:web/webmvc/mvc-config/api-version.adoc[supported version].
802+
803+
See xref:web/webmvc-versioning.adoc[API Versioning] for more details on underlying
804+
infrastructure and support for API Versioning.
805+
806+
807+
808+
764809
[[webmvc-fn-serving-resources]]
765810
== Serving Resources
766811

framework-docs/modules/ROOT/pages/web/webmvc-versioning.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Please, see also related content in:
1212
- Configure xref:web/webmvc/mvc-config/api-version.adoc[API versioning] in the MVC Config
1313
- xref:web/webmvc/mvc-controller/ann-requestmapping.adoc#mvc-ann-requestmapping-version[Map requests]
1414
to annotated controller methods with an API version
15+
- xref:web/webmvc-functional.adoc#api-version[Route requests]
16+
to functional endpoints with an API version
1517

1618
Client support for API versioning is available also in `RestClient`, `WebClient`, and
1719
xref:integration/rest-clients.adoc#rest-http-interface[HTTP Service] clients, as well as

framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-requestmapping.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,10 @@ In this scenario, a `NotAcceptableApiVersionException` results in a 400 response
505505

506506
NOTE: The above assumes the request version is a
507507
xref:web/webmvc/mvc-config/api-version.adoc["supported" version], or otherwise it
508-
would fail xref:web/webmvc-versioning.adoc#mvc-versioning-validation[Validation].
508+
would fail.
509509

510+
See xref:web/webmvc-versioning.adoc[API Versioning] for more details on underlying
511+
infrastructure and support for API Versioning.
510512

511513

512514

0 commit comments

Comments
 (0)