Skip to content

keepeek-rd/gravitee-policy-dynamic-routing

 
 

Repository files navigation

Dynamic routing policy

Build status Gitter

Phase

onRequest onResponse

X

Description

The dynamic-routing policy is used to dispatch inbound calls to different targets / endpoints or to rewrite URIs.

This policy is particularly useful for creating API Mashups.

Another typical use case is defining this kind of routing:

Attributes

Name Description

request.endpoint

The endpoint URL invoked by the gateway after dynamic routing

Configuration

You can configure multiple rules and their respective redirections relative to the initial request path.

Warning
When you define rules, it is important to remember that the API context-path must not be part of the rule’s path. For example, if your context-path is /myapi and your call is /myapi/123, if you want to select 123 the regular expression is /(.*) (don’t forget the /).

Regular expressions

Using regular expressions can be very useful when you want to capture some parts of the initial request path and reuse them to define the redirection.

For example, to capture the end of a path after /v1/stores/, the rule path is /v1/stores/(.*). You can then use it in the redirect to property: http://store_backend/stores/{#group[[0]]}

You can also use named groups instead of indexed groups: /api/(?<version>v[0-9]+)/stores.*http://host1/products/api/{#groupName['version']}

Examples

"dynamic-routing": {
    "rules": [
        {
            "pattern": "/v1/stores/(.*)",
            "url": "http://host2/stores/{#group[0]}"
        }
    ]
}

You can also select endpoints configured for your API by name using expression language:

"dynamic-routing": {
    "rules": [
        {
            "pattern": "/v1/stores/(.*)",
            "url": "{#endpoints['default']}/{#group[0]}"
        }
    ]
}

Errors

HTTP status code

Code Message

400

When no rules match the inbound request

About

Gravitee Policy - Dynamic Routing

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%