* Rename Fallback::Custom to Fallback::Service
* Allow Routers to inherit state
* Rename Router::{nest => nest_service} and add new nest method for Routers
* Fix lints
* Add basic tests for state inheritance
* Changelog
* Support `State` with `#[derive(FromRequest[Parts])]`
Fixes https://github.com/tokio-rs/axum/issues/1314
This makes it possible to extract things via `State` in
`#[derive(FromRequet)]`:
```rust
struct Foo {
state: State<AppState>,
}
```
The state can also be inferred in a lot of cases so you only need to
write:
```rust
struct Foo {
// since we're using `State<AppState>` we know the state has to be
// `AppState`
state: State<AppState>,
}
```
Same for
```rust
struct Foo {
#[from_request(via(State))]
state: AppState,
}
```
And
```rust
struct AppState {}
```
I think I've covered all the edge cases but there are (unsurprisingly) a
few.
* make sure things can be combined with other extractors
* main functions in ui tests don't need to be async
* Add test for multiple identicaly state types
* Add failing test for multiple states
* Use `400 Bad Request` for `FailedToDeserializeQueryString` rejections
Fixes https://github.com/tokio-rs/axum/issues/1378
From [the spec] about `422 Unprocessable Entity`:
> For example, this error condition may occur if an XML request body
> contains well-formed (i.e., syntactically correct), but semantically
> erroneous, XML instructions.
I understand this to mean that query params shouldn't use 422 because
that is about the request body.
So this changes `FailedToDeserializeQueryString` from `422 Unprocessable
Entity` to `400 Bad Request`.
[the spec]: https://datatracker.ietf.org/doc/html/rfc4918#section-11.2
* changelog
Previously, it was difficult to find out the path in the deep JSON tree at
which a deserialization error occurred. This patch makes an error message
to contain the errored path. In order to find out the path,
I added serde_path_to_error, a new optional dependency.
Co-authored-by: Lee Dogeon <dev.moreal@gmail.com>
Co-authored-by: Lee Dogeon <dev.moreal@gmail.com>
* Refactor proc-macro attribute parsing
* Remove `#[allow(warnings)]` which was accidentally committed
* Change span for "cannot use `rejection` without `via`" error for enums
* fix test
* [doc] Added notes about extractor precedence
Both JSON and Form extractors consume the Body when they run, so they
need to be last in the order of extractors.
Added a note in the structs docs themselves pointing to the relevant
part of the documentation.
* Address review comments
- Added documentation snippet to BodyStream, RawBody, Multipart
- Added documentation about the inner type of ContentLengthLimit
- Fixed link type in State
* Update axum/src/extract/content_length_limit.rs
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
* Cargo fmt didn't run for some reason
I need to check my editor config...
* Apply suggestions from code review
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
* Add targets to links
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
* Add example for parsing body based on `Content-Type`
* format
* Update examples/parse-body-based-on-content-type/src/main.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
* fix copy/paste errors
* rename type params
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
* Explicitely point out example dependency
Save the next visitor to that docs page the trouble of having to figure
out why a Path<Uuid> extractor results in a cryptic error by default.
* Update axum/src/extract/path/mod.rs
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
* Add missing leading double colon
* Separate handling of last element in FromRequest derive
* FromRequestParts derive
* fix it and add lots of tests
* docs
* changelog
* Update axum-macros/src/lib.rs
Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>