📗
Janus Manual
  • Introduction
  • Installation
    • Docker
  • Quick Start
    • Authenticating
    • Add an endpoint
    • Modify (Update/Delete) an endpoint
    • Add Plugins
    • Authentication
    • Adding your API - File System
  • Clustering/HA
  • Proxy Reference
    • Terminology
    • Overview
    • Routing capabilities
    • Load Balacing
    • Request Host header
      • Using wildcard hostnames
      • The preserve_host property
    • Request URI
      • The strip_path property
      • The append_path property
    • Request HTTP method
    • Routing priorities
    • Conclusion
  • Plugins
    • Basic
    • Organization
    • Body Limit
    • Circuit Breaker
    • Compression
    • CORS
    • OAuth
    • Rate Limit
    • Request Transformer
    • Response Transformer
    • Retry
  • Auth
    • OAuth 2.0
  • Misc
    • Health Checks
    • Monitoring
    • Tracing
  • Known Issues
    • Stale HTTP Keep-Alive
  • Upgrade Notes
    • 2.x to 3.x
    • 3.6.x to 3.7.x
Powered by GitBook
On this page

Was this helpful?

  1. Proxy Reference

Routing priorities

An API may define matching rules based on its hosts, listen_path, and methods fields. For Janus to match an incoming request to an API, all existing fields must be satisfied. However, Janus allows for quite some flexibility by allowing two or more APIs to be configured with fields containing the same values - when this occurs, Janus applies a priority rule.

The rule is that : when evaluating a request, Janus will first try to match the APIs with the most rules.

For example, two APIs are configured like this:

{
    "name": "API 1",
    "proxy": {
        "listen_path": "/",
        "upstreams" : {
            "balancing": "roundrobin",
            "targets": [
                {"target": "http://my-api.com"}
            ]
        },
        "hosts": ["example.com"]
    }
},
{
    "name": "API 2",
    "proxy": {
        "listen_path": "/",
        "upstreams" : {
            "balancing": "roundrobin",
            "targets": [
                {"target": "http://my-api.com"}
            ]
        },
        "hosts": ["example.com"],
        "methods": ["POST"]
    }
}

api-2 has a hosts field and a methods field, so it will be evaluated first by Janus. By doing so, we avoid api-1 "shadowing" calls intended for api-2.

Thus, this request will match api-1:

GET / HTTP/1.1
Host: example.com

And this request will match api-2:

POST / HTTP/1.1
Host: example.com

Following this logic, if a third API was to be configured with a hosts field, a methods field, and a listen_path field, it would be evaluated first by Janus.

PreviousRequest HTTP methodNextConclusion

Last updated 4 years ago

Was this helpful?