-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OptionalPath extractor #1884
Comments
pub(crate) async fn handler(
path: Option<Path<String>>,
) -> impl IntoResponse
{
..
} |
Yes, that works most of the time, but it doesn't reject the request for @davidpdrsn wdyt about this idea? |
I'm wondering if we can change |
Yeah, the idea was to put it in axum-extra, and implement it in terms of |
Then I think it's a good idea! I don't specifically remember if its possible today but looking at pub enum PathRejection {
FailedToDeserializePathParams(FailedToDeserializePathParams),
MissingPathParams(MissingPathParams),
}
|
Looking at |
Feature Request
Motivation
We've been getting many people asking about an easy way of extracting a path segment value only if a placeholder exists at the route the handler was called from.
Proposal
Add an extractor
struct OptionalPath<T>(Option<T>);
that succeeds withNone
if there are no placeholders for the given route, and if there are placeholders, attempts to deserialize the arguments toT
and returnSome(T)
on success, rejecting the request on failure.Alternatives
🤷🏼
The text was updated successfully, but these errors were encountered: