Spring-cloud-gateway: how to match different PredicateFactory according to the request method?

Created on 12 Dec 2018  Â·  2Comments  Â·  Source: spring-cloud/spring-cloud-gateway

when the http request is post method, i want to match readBody predicate, when the request is get method, i don‘t want to match any predicate, how to achieve it?i will appreciate it.

question

All 2 comments

You should use the Method=GET predicate before the read body

@xiaozhiliaoo you could define two different routes, like so:

@Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route(r -> r.method(HttpMethod.POST).and().readBody(YourClass.class, yourPredicate()).uri("http://example.org"))
                .route(r -> r.method(HttpMethod.GET).uri("http://example.org"))
                .build();
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ShahzebAnsari picture ShahzebAnsari  Â·  3Comments

dennis-menge picture dennis-menge  Â·  4Comments

larva2333 picture larva2333  Â·  6Comments

samtonyclarke picture samtonyclarke  Â·  3Comments

aresa7796 picture aresa7796  Â·  6Comments