Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adriangb/asgi-routing
https://github.com/adriangb/asgi-routing
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/adriangb/asgi-routing
- Owner: adriangb
- License: mit
- Created: 2022-07-14T05:26:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-27T03:08:02.000Z (about 2 years ago)
- Last Synced: 2024-10-07T18:08:31.271Z (about 1 month ago)
- Language: Jupyter Notebook
- Size: 220 KB
- Stars: 14
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-asgi - asgi-routing - A high performance router written in Rust for the ASGI ecosystem. Built on top of `routrie` and `path-tree`. (Resources / Experiments and examples)
README
# asgi-routing
A high performance router written in 🦀 for the ASGI ecosystem.
Built on top of [routrie] and [path-tree].[routrie]: https://github.com/adriangb/routrie
[path-tree]: https://github.com/viz-rs/path-tree## Features
* Pure ASGI, compatible with any ASGI web framework.
* Very fast, we use a radix-tree router written in Rust.
* Support for all of the common routing primitives like path parameters and catch-all parameters.## Example
We'll be using Starlette's `Response` object to handle some ASGI boilerplate that is not relevant to this example.
```python
from starlette.responses import PlainTextResponsefrom asgi_routing import Mount, Route, Router
app = Router(
[
Route("/", PlainTextResponse("home")),
Mount(
"/users",
Router(
[
Route("/me", PlainTextResponse("me")),
Route("/{username}", PlainTextResponse("you")),
Route("/{username}/disable", PlainTextResponse("bye")),
Route("/nomatch", PlainTextResponse("who?")),
]
),
),
]
)
```Since this is a pure ASGI router, you can also mount it to a specific path in a Starlette app if you know that that path is high traffic or has a very large routing table.
You won't see much of a difference compared to Starlette's built in router unless you have 20+ routes.
See [benchmarks] for more details.[benchmarks]: https://github.com/xpresso-devs/asgi-routing/blob/main/bench.ipynb