pub struct ProblemJson<T>(pub T);Expand description
The problem-flavored sibling of ApiJson: deserializes a
JSON request body exactly like axum::Json, but extraction failures reject
with an RFC 9457 Problem body via ProblemRejection.
Status codes and the stable code extension member match
ApiJson’s rejections exactly:
- malformed JSON ->
400 Bad Request, codeINVALID_JSON - well-formed JSON of the wrong shape ->
422 Unprocessable Entity, codeINVALID_BODY - missing or incorrect
Content-Type->415 Unsupported Media Type, codeUNSUPPORTED_MEDIA_TYPE
The problem body carries the same information the flat rejection would:
detail is the same human-readable message, the stable code becomes the
"code" extension member, and title comes from the status’s canonical
reason. The Content-Type is negotiated from the request’s Accept
headers via ProblemFormat::negotiate. It also implements
IntoResponse (serializing as 200 OK plain JSON), so it can be used
as a handler return type just like ApiJson.
Requires the problem and extract features.
§Example
use axum_api_kit::ProblemJson;
use serde::Deserialize;
#[derive(Deserialize)]
struct CreateUser {
name: String,
}
// Bad input short-circuits with an RFC 9457 problem details body.
async fn create_user(ProblemJson(user): ProblemJson<CreateUser>) {
let _ = user.name;
}Tuple Fields§
§0: TTrait Implementations§
Source§impl<T: Clone> Clone for ProblemJson<T>
impl<T: Clone> Clone for ProblemJson<T>
Source§fn clone(&self) -> ProblemJson<T>
fn clone(&self) -> ProblemJson<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for ProblemJson<T>
impl<T: Debug> Debug for ProblemJson<T>
Source§impl<T, S> FromRequest<S> for ProblemJson<T>
Available on crate feature extract only.
impl<T, S> FromRequest<S> for ProblemJson<T>
extract only.Source§impl<T: Serialize> IntoResponse for ProblemJson<T>
Available on crate feature extract only.
impl<T: Serialize> IntoResponse for ProblemJson<T>
extract only.Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Auto Trait Implementations§
impl<T> Freeze for ProblemJson<T>where
T: Freeze,
impl<T> RefUnwindSafe for ProblemJson<T>where
T: RefUnwindSafe,
impl<T> Send for ProblemJson<T>where
T: Send,
impl<T> Sync for ProblemJson<T>where
T: Sync,
impl<T> Unpin for ProblemJson<T>where
T: Unpin,
impl<T> UnsafeUnpin for ProblemJson<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for ProblemJson<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
Source§fn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
Source§fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
tower::Layer to the handler. Read moreSource§fn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Service by providing the stateSource§impl<H, T> HandlerWithoutStateExt<T> for H
impl<H, T> HandlerWithoutStateExt<T> for H
Source§fn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Service and no state.Source§fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
MakeService and no state. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more