Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

add host-based routing docs #1313

Merged
merged 9 commits into from Oct 25, 2021
21 changes: 21 additions & 0 deletions docs/routing.md
Expand Up @@ -217,3 +217,24 @@ app = Router(routes=[
])
])
```

## Host-based routing
WhiteApfel marked this conversation as resolved.
Show resolved Hide resolved

If you want to use different routes for the same path based on the `Host` header

```python
site = Router() # Use eg. `@site.route()` to configure this.
api = Router() # Use eg. `@api.route()` to configure this.
news = Router() # Use eg. `@news.route()` to configure this.

routes = [
Host('api.example.org', api)
]

app = Starlette(routes=routes)

app.host('www.example.org', site)

news_host = Host('news.example.org', news)
app.router.routes.append(news_host)
```