mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-13 00:00:35 +02:00
Previously, on `main`, this wouldn't compile:
```rust
let app = route("/", get(handler))
.layer(
ServiceBuilder::new()
.timeout(Duration::from_secs(10))
.into_inner(),
)
.handle_error(...)
.route(...); // <-- doesn't work
```
That is because `handle_error` would be
`axum::service::ServiceExt::handle_error` which returns `HandleError<_,
_, _, HandleErrorFromService>` which does _not_ implement `RoutingDsl`.
So you couldn't call `route`. This was caused by
https://github.com/tokio-rs/axum/pull/120.
Basically `handle_error` when called on a `RoutingDsl`, the resulting
service should also implement `RoutingDsl`, but if called on another
random service it should _not_ implement `RoutingDsl`.
I don't think thats possible by having `handle_error` on `ServiceExt`
which is implemented for any service, since all axum routers are also
services by design.
This resolves the issue by removing `ServiceExt` and moving its methods
to `RoutingDsl`. Then we have more tight control over what has a
`handle_error` method.
`service::OnMethod` now also has a `handle_error` so you can still
handle errors from random services, by doing
`service::any(svc).handle_error(...)`.
Examples
hello_world- Very small getting started app.todos- Provides a RESTful web server managing some Todos.key_value_store- Slightly larger app with an in-memory key/value store.form- Receiving data from an HTML<form>.multipart_form- How to parsemultipart/form-dataforms.static_file_server- Serving static files from a directory. Could for example be the baseline for a single page app.templates- Rending HTML templates using askama.testing- How to test axum apps.versioning- How one might version an API.websocket- How to build an app that handles WebSocket connections.error_handling_and_dependency_injection- How to handle errors and dependency injection using trait objects.tokio_postgres- How to use a tokio-postgres and bb8 to query a database.unix_domain_socket- How to run an Axum server over unix domain sockets.sessions- Sessions and cookies usingasync-session.tls_rustls- TLS withtokio-rustls.chat- Chat application example.404- Custom 404 page.async-graphql- GraphQL example usingasync-graphql.tracing_aka_logging- How to setup and configure tracing/logging.
Community showcase
- Houseflow: House automation platform written in Rust.