github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/docs/proxy/routing_priorities.md (about) 1 ### Routing priorities 2 3 An API may define matching rules based on its `hosts`, `listen_path`, and `methods` 4 fields. For Janus to match an incoming request to an API, all existing fields 5 must be satisfied. However, Janus allows for quite some flexibility by allowing 6 two or more APIs to be configured with fields containing the same values - when 7 this occurs, Janus applies a priority rule. 8 9 The rule is that : **when evaluating a request, Janus will first try 10 to match the APIs with the most rules**. 11 12 For example, two APIs are configured like this: 13 14 ```json 15 { 16 "name": "API 1", 17 "proxy": { 18 "listen_path": "/", 19 "upstreams" : { 20 "balancing": "roundrobin", 21 "targets": [ 22 {"target": "http://my-api.com"} 23 ] 24 }, 25 "hosts": ["example.com"] 26 } 27 }, 28 { 29 "name": "API 2", 30 "proxy": { 31 "listen_path": "/", 32 "upstreams" : { 33 "balancing": "roundrobin", 34 "targets": [ 35 {"target": "http://my-api.com"} 36 ] 37 }, 38 "hosts": ["example.com"], 39 "methods": ["POST"] 40 } 41 } 42 ``` 43 44 api-2 has a `hosts` field **and** a `methods` field, so it will be 45 evaluated first by Janus. By doing so, we avoid api-1 "shadowing" calls 46 intended for api-2. 47 48 Thus, this request will match api-1: 49 50 ```http 51 GET / HTTP/1.1 52 Host: example.com 53 ``` 54 55 And this request will match api-2: 56 57 ```http 58 POST / HTTP/1.1 59 Host: example.com 60 ``` 61 62 Following this logic, if a third API was to be configured with a `hosts` field, 63 a `methods` field, and a `listen_path` field, it would be evaluated first by Janus.