Skip to content

Commit 925c822

Browse files
committed
Document Path predicate fully expanded argument format
Add documentation for using the Path predicate with fully expanded arguments, including indexed key notation (patterns.0, patterns.1) for list parameters. This clarifies the naming convention when configuring routes via the Actuator API or programmatically. Fixes gh-3523
1 parent beaa38b commit 925c822

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

docs/modules/ROOT/pages/spring-cloud-gateway-server-webflux/request-predicates-factories.adoc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,52 @@ This route matches if the request path was, for example: `/red/1` or `/red/1/` o
208208

209209
If `matchTrailingSlash` is set to `false`, then request path `/red/1/` will not be matched.
210210

211+
[[path-route-predicate-factory-expanded-arguments]]
212+
=== Fully Expanded Arguments
213+
214+
When using the fully expanded argument format (for example, when configuring routes via the Actuator API or programmatically), the `Path` predicate uses indexed keys for list parameters. The following example shows the fully expanded configuration:
215+
216+
.application.yml
217+
[source,yaml]
218+
----
219+
spring:
220+
cloud:
221+
gateway:
222+
server:
223+
webflux:
224+
routes:
225+
- id: path_route
226+
uri: https://example.org
227+
predicates:
228+
- name: Path
229+
args:
230+
patterns.0: /red/{segment}
231+
patterns.1: /blue/{segment}
232+
matchTrailingSlash: false
233+
----
234+
235+
When posting route definitions via the Actuator API, use the same indexed notation in the JSON request body:
236+
237+
[source,json]
238+
----
239+
{
240+
"id": "path_route",
241+
"uri": "https://example.org",
242+
"predicates": [
243+
{
244+
"name": "Path",
245+
"args": {
246+
"patterns.0": "/red/{segment}",
247+
"patterns.1": "/blue/{segment}",
248+
"matchTrailingSlash": "false"
249+
}
250+
}
251+
]
252+
}
253+
----
254+
255+
NOTE: The `args` map accepts only `String` key-value pairs. List parameters like `patterns` must be specified using indexed keys (`patterns.0`, `patterns.1`, etc.) rather than JSON arrays. This indexed notation is automatically converted to a `List<String>` when the predicate is configured.
256+
211257
If you have set `spring.webflux.base-path` property, this will influence the path matching. The property value will be automatically prepended to the path patterns. For example, with `spring.webflux.base-path=/app` and a path pattern of `/red/\{segment\}`, the full pattern used for matching would be `/app/red/\{segment\}`.
212258

213259
This predicate extracts the URI template variables (such as `segment`, defined in the preceding example) as a map of names and values and places it in the `ServerWebExchange.getAttributes()` with a key defined in `ServerWebExchangeUtils.URI_TEMPLATE_VARIABLES_ATTRIBUTE`.

0 commit comments

Comments
 (0)