You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/04/07 01:10:53 UTC

[GitHub] [apisix] tokers commented on a change in pull request #3987: docs: add more example about how to use the router radixtree-uri

tokers commented on a change in pull request #3987:
URL: https://github.com/apache/apisix/pull/3987#discussion_r608274301



##########
File path: docs/en/latest/router-radixtree.md
##########
@@ -71,7 +71,98 @@ Here are the rules:
 |/blog/foo/gloo | `/blog/foo/*` |
 |/blog/bar | not match |
 
-#### 4. Parameter match
+#### 4. Different routes have the same `uri`
+
+When different routes have the same uri, you can set the priority field of the route to determine which route to match first, or add other matching rules to distinguish different routes.
+
+Note: In matching rules, the `priority` field takes precedence over other rules.
+
+1. Different routes have the same `uri` and set the `priority` field
+
+Create two routes with different `priority` values ​​(the larger the value, the higher the priority).
+
+```shell
+$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "upstream": {
+       "nodes": {
+           "127.0.0.1:1980": 1
+       },
+       "type": "roundrobin"
+    },
+    "priority": 3,
+    "uri": "/hello"
+}'
+```
+
+```shell
+$ curl http://127.0.0.1:9080/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "upstream": {
+       "nodes": {
+           "127.0.0.1:1981": 1
+       },
+       "type": "roundrobin"
+    },
+    "priority": 2,
+    "uri": "/hello"
+}'
+```
+
+Test:
+
+```shell
+curl http://127.0.0.1:1980/hello
+1980
+```
+
+All requests only hit the route of port `1980`.
+
+2. Different routes have the same `uri` and set different matching conditions
+
+Here is an example of setting host matching rules:
+
+```shell
+$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "upstream": {
+       "nodes": {
+           "127.0.0.1:1980": 1
+       },
+       "type": "roundrobin"
+    },
+    "hosts": ["localhost.com"],
+    "uri": "/hello"
+}'
+```
+
+```shell
+$ curl http://127.0.0.1:9080/apisix/admin/routes/2 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "upstream": {
+       "nodes": {
+           "127.0.0.1:1981": 1
+       },
+       "type": "roundrobin"
+    },
+    "hosts": ["test.com"],
+    "uri": "/hello"
+}'
+```
+
+Test:
+
+```shell
+$ curl http://127.0.0.1:9080/hello -H 'host: localhost.com'
+1980
+```
+
+```shell
+$ curl http://127.0.0.1:9080/hello -H 'host: test.com'
+1981
+```
+

Review comment:
       Add some concise descriptions?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org