-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* router reference * Check * Add Router doc and reference doc * vale * Apply suggestions from code review Co-authored-by: Diana <75819066+cloudjumpercat@users.noreply.github.com> * suggestions from code review Co-authored-by: Diana <75819066+cloudjumpercat@users.noreply.github.com>
- Loading branch information
1 parent
996b7ba
commit b5f34a0
Showing
4 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
title: Router Operator Reference for Kong Gateway | ||
content-type: reference | ||
--- | ||
|
||
With the release of version 3.0, {{site.base_gateway}} now ships with a new router. The new router can describe routes using a domain-specific language called Expressions. Expressions can describe routes or paths as patterns using regular expressions. This document serves as a reference for all of the available operators. If you want to learn how to configure routes using Expressions read [How to configure routes using Expressions](gateway/latest/understanding-kong/how-to/router-atc/). | ||
|
||
|
||
## Available fields | ||
|
||
| Field | Description | | ||
| --- | ----------- | | ||
| `net.protocol` | The protocol used to communicate with the upstream application. | | ||
| `tls.sni` | Server name indication. | | ||
| `http.method` | HTTP methods that match a route. | | ||
| `http.host` | Lists of domains that match a route. | | ||
| `http.path` | Returns or sets the path. | | ||
| `http.raw_path` | Returns or sets the escaped path. | | ||
| `http.headers.*` | Lists of values that are expected in the header of a request. | | ||
|
||
## String | ||
|
||
| Operator | Name | Return Type | | ||
| --- | ----------- | --- | | ||
| == | Equals | Boolean| | ||
| != | Not equals | Boolean| | ||
| ~ | Regex matching | Boolean| | ||
| ^= | Prefix matching | Boolean| | ||
| =^ | Suffix matching | Boolean| | ||
| in | Contains | Boolean| | ||
| not in | Does not contain | Boolean| | ||
| lower() | Lowercase | String| | ||
|
||
## Integer | ||
|
||
| Operator | Name | Return Type | | ||
| --- | ----------- | --- | | ||
| == | Equals | Boolean| | ||
| != | Not equals| Boolean| | ||
| > | Greater than | Boolean| | ||
| >= | Greater than or equal | Boolean| | ||
| < | Less than | Boolean| | ||
| <= | Less than or equal | Boolean| | ||
|
||
## IP | ||
|
||
| Operator | Name | Return Type | | ||
| --- | ----------- | --- | | ||
| == | Equals | Boolean| | ||
| != | Not equals | Boolean| | ||
| in | Contains | Boolean| | ||
|
||
## Boolean | ||
|
||
| Operator | Name | Return Type | | ||
| --- | ----------- | --- | | ||
| && | And | Boolean| | ||
| `||` | Or | Boolean| | ||
| ! | Not | Boolean| | ||
|
||
|
||
|
||
## More information | ||
|
||
* [Expressions repository](https://github.com/Kong/atc-router#table-of-contents) | ||
* [How to configure routes using Expressions](gateway/latest/understanding-kong/how-to/router-atc/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
title: How to Configure Routes using Expressions | ||
content-type: how-to | ||
--- | ||
|
||
|
||
Expressions can describe routes or paths as patterns using regular expressions. This how-to guide will walk through switching to the new router, and configuring routes with the new expressive domain specific language, expressions. For a list of all available operators and configurable fields please review the [reference documentation](/gateway/latest/reference/router-operators). | ||
|
||
## Prerequisite | ||
|
||
Edit [kong.conf](/gateway/latest/kong-production/kong-conf) to contain the line `router_flavor = expressions` and restart {{site.base_gateway}}. | ||
|
||
## Create routes with Expressions | ||
|
||
To create a new router object using expressions, send a `POST` request to the [services endpoint](/gateway/latest/admin-api/#update-route) like this: | ||
```sh | ||
curl --request POST \ | ||
--url http://localhost:8001/services/example-service/routes \ | ||
--form atc='http.path == "/mock" | ||
``` | ||
In this example, you associated a new route object with the path `/mock` to the existing service `example-service`. The Expressions DSL also allows you to create complex router objects using operators. | ||
```sh | ||
curl --request POST \ | ||
--url http://localhost:8001/services/example-service/routes \ | ||
--header 'Content-Type: multipart/form-data' \ | ||
--form 'atc=(http.path == "/mock" || net.protocol == "https")' | ||
``` | ||
In this example the || operator created an expression that set variables for the following fields: | ||
``` | ||
"protocols": ["http", "https"] | ||
AND | ||
"paths": ["/mock"] | ||
``` | ||
You can use attributes that are unrelated to expressions within the same `POST` request: | ||
```sh | ||
curl --request POST \ | ||
--url http://localhost:8001/services/example-service/routes \ | ||
--header 'Content-Type: multipart/form-data' \ | ||
--form 'atc=(http.path == "/mock" || net.protocol == "https") \ | ||
--form name=mocking | ||
``` | ||
|
||
This would define a router object with the following attributes: | ||
|
||
|
||
``` | ||
"atc": "(http.path == \"\/mock\" || net.protocol == \"https\"), | ||
"name": "mocking", | ||
``` | ||
You can view the list of available attributes in the [reference documentation](/gateway/latest/admin-api/#request-body). | ||
|
||
|
||
|
||
### Create complex routes with Expressions | ||
|
||
You can describe complex route objects using operators within a `POST` request. | ||
|
||
```sh | ||
|
||
curl --request POST \ | ||
--url http://localhost:8001/services/example-service/routes \ | ||
--header 'Content-Type: multipart/form-data' \ | ||
--form name=complex_object \ | ||
--form 'atc=(net.protocol == "http" || net.protocol == "https") && | ||
(http.method == "GET" || http.method == "POST") && | ||
(http.host == "example.com" || http.host == "example.test") && | ||
(http.path ^= "/mock" || http.path ^= "/mocking") && | ||
http.headers.x_another_header == "example_header" && (http.headers.x_my_header == "example" || http.headers.x_my_header == "example2")' | ||
``` | ||
|
||
This request returns a `200` status code with the following values: | ||
|
||
```sh | ||
"protocols": ["http", "https"], | ||
"methods": ["GET", "POST"], | ||
"hosts": ["example.com", "example.test"], | ||
"paths": ["/mock", "/mocking"], | ||
"headers": {"x-another-header":["example_header"], "x-my-header":["example", "example2"]}, | ||
``` | ||
|
||
For a list of all available operators, see the [reference documentation](/gateway/latest/reference/router-operators/). | ||
|
||
|
||
## More information | ||
|
||
* [Expressions repository](https://github.com/Kong/atc-router#table-of-contents) | ||
* [Expressions Reference](/gateway/latest/reference/router-operators) |