Santosh Ksl
Santosh Ksl

Reputation: 314

Spring Cloud Gateway Query Predicate OR Condition

I'm working on Spring Cloud Gateway where I wanted to define a route with Query predicate, where this route should be matched when any of the Query Param Values matches.

For example: I'm looking for a scenario where a single Query Predicate can take multiple matching values. Is this possible ?

- id: test-api
  uri: http://www.myhost.com
  predicates:
   - Path=/v3/test/
   - Method=POST
   - Query=key,value_1,value_2
     

Spring Cloud documentation only speaks about matching a single value for Query Predicate - https://cloud.spring.io/spring-cloud-gateway/multi/multi_gateway-request-predicates-factories.html#_query_route_predicate_factory

Upvotes: 1

Views: 3529

Answers (1)

Santosh Ksl
Santosh Ksl

Reputation: 314

I have found the way to specify multiple query params matches.

As per the spring documentation https://cloud.spring.io/spring-cloud-gateway/multi/multi_gateway-request-predicates-factories.html#_query_route_predicate_factory

the value of it is a regex string. so it can be done by specifying values separated by | operator

- id: test-api
  uri: http://www.myhost.com
  predicates:
   - Path=/v3/test/
   - Method=POST
   - Query=key, value_1|value_2

Upvotes: 3

Related Questions