Skip to content

k4m-git/gravitee-policy-dynamic-routing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 can be particularly useful when user needs to prepare a mashup of APIs into a single one.

An other typical use-case will be to define this kind of routing:

Attributes

Name Description

request.endpoint

The endpoint URL invoked by the gateway after dynamic routing.

Configuration

When using the Dynamic Routing policy, you can define multiple rules and their respective redirections according to the initial request path.

Warning
When defining rule, please consider that the API’s context-path must not be part of the rule’s path! If your context-path is /myapi and your call is /myapi/123, if you want to select 123 the regular expression will be /(.*). Don’t forget the /.

Regular expressions

Rules can be defined using regular expression: /v1/stores/(.*).

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: the rule’s path is /v1/stores/(.*) to capture the end of the path after /v1/stores/ and use it in the redirect to property: http://store_backend/stores/{#group[0]}

An other great feature is the possibility to use named group instead of indexed group. /api/(?<version>v[0-9]+)/stores.*http://host1/products/api/{#groupName['version']}

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

It’s also possible to select a configured endpoint on your API, by its name using expression language.

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

Http Status Code

Code Message

400

When no rule match the inbound request

About

Gravitee Policy - Dynamic Routing

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages