Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To configure a simple route in Spring Cloud Gateway Server WebFlux 5.0.3, add a route under spring.cloud.gateway.server.webflux.routes, give it a destination URI, and use a Path predicate to select requests. The example below matches /hello and forwards matching requests to https://example.org.

Configure a basic WebFlux route

Add this configuration to your application’s YAML configuration file:

spring:
  cloud:
    gateway:
      server:
        webflux:
          routes:
            - id: simple_route
              uri: https://example.org
              predicates:
                - Path=/hello

Replace https://example.org with the URI of the downstream service that should receive matching requests.

  • spring.cloud.gateway.server.webflux.routes is the route configuration property prefix documented for Spring Cloud Gateway Server WebFlux 5.0.3.
  • id: simple_route gives the route an identifier.
  • uri specifies the downstream destination.
  • Path=/hello is a predicate: it matches requests whose path is /hello.

When the predicate matches, the gateway routes the request to the configured destination. Spring Cloud Gateway describes a route as an ID, destination URI, collection of predicates, and collection of filters. A route matches when its combined predicate is true. Spring Cloud Gateway Glossary

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a predicate syntax

For a simple path match, the compact shortcut form used above is easy to scan. Spring Cloud Gateway also supports expanded YAML, which makes the predicate name and its arguments explicit. The reference demonstrates both styles for predicate and filter arguments. Predicate and filter configuration reference

Style Example When it helps
Shortcut - Path=/hello Compact configuration for a predicate with straightforward arguments.
Expanded
- name: Path
  args:
    patterns: /hello
Makes the predicate name and argument key visible in YAML.

Predicate argument names depend on the predicate factory. Use the documented argument names for the predicate you configure; the reference’s cookie example, for instance, uses name: Cookie with named values under args.

Combine conditions when a route needs them

You can add more than one predicate to a route. Spring Cloud Gateway combines route predicate factories using logical AND, so every configured predicate must match for the route to match. Add another condition only when requests must satisfy both it and the path condition.

When to add a filter

A filter is not required for the basic forwarding route above. Add a gateway filter when you need to change a request before downstream handling or modify a response afterward. Spring Cloud Gateway’s glossary describes filters as the route component used for those request or response changes. Spring Cloud Gateway Glossary

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check the version and server variant

The property prefix in the example is for Spring Cloud Gateway Server WebFlux 5.0.3. Property keys can differ between releases and server variants, so check the configuration reference for the exact version and variant in your application before copying the example. In particular, this WebFlux configuration should not be assumed to apply unchanged to Spring Cloud Gateway Server WebMVC. The official properties references document the WebFlux prefix. Common application properties · Configuration Properties

Spring Cloud Gateway’s project overview describes its goal as routing to APIs while supporting cross-cutting concerns such as security, monitoring and metrics, and resiliency. Spring Cloud Gateway project overview

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.