pub struct Response {
pub status: StatusCode,
pub data: Value,
pub message: Option<String>,
}
Expand description
HTTP response wrapper
Fields§
§status: StatusCode
The response status code
data: Value
The response data
message: Option<String>
Optional success message
Implementations§
Source§impl Response
impl Response
Sourcepub fn new(status: StatusCode, data: Value) -> Self
pub fn new(status: StatusCode, data: Value) -> Self
Creates a new response
Sourcepub fn with_message(status: StatusCode, data: Value, message: String) -> Self
pub fn with_message(status: StatusCode, data: Value, message: String) -> Self
Creates a new response with a message
Sourcepub fn success(data: Value, message: Option<String>) -> Result<Self>
pub fn success(data: Value, message: Option<String>) -> Result<Self>
Creates a successful response with message
Sourcepub fn no_content() -> Result<Self>
pub fn no_content() -> Result<Self>
Creates a no content response (204 No Content)
Sourcepub fn bad_request<S: Into<String>>(message: S) -> Result<Self>
pub fn bad_request<S: Into<String>>(message: S) -> Result<Self>
Creates a bad request response (400 Bad Request)
Creates an unauthorized response (401 Unauthorized)
Sourcepub fn forbidden<S: Into<String>>(message: S) -> Result<Self>
pub fn forbidden<S: Into<String>>(message: S) -> Result<Self>
Creates a forbidden response (403 Forbidden)
Sourcepub fn not_found<S: Into<String>>(message: S) -> Result<Self>
pub fn not_found<S: Into<String>>(message: S) -> Result<Self>
Creates a not found response (404 Not Found)
Sourcepub fn internal_error<S: Into<String>>(message: S) -> Result<Self>
pub fn internal_error<S: Into<String>>(message: S) -> Result<Self>
Creates an internal server error response (500 Internal Server Error)
Sourcepub fn with_message_str<S: Into<String>>(self, message: S) -> Self
pub fn with_message_str<S: Into<String>>(self, message: S) -> Self
Adds a message to the response
Trait Implementations§
Source§impl IntoResponse for Response
impl IntoResponse for Response
Source§fn into_response(self) -> AxumResponse
fn into_response(self) -> AxumResponse
Create a response.
Auto Trait Implementations§
impl Freeze for Response
impl RefUnwindSafe for Response
impl Send for Response
impl Sync for Response
impl Unpin for Response
impl UnwindSafe for Response
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
Mutably borrows from an owned value. Read more
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
Call the handler with the given request.
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>>,
Apply a
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>
Convert the handler into a
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, ()>
Convert the handler into a
Service
and no state.Source§fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
Convert the handler into a
MakeService
and no state. Read moreSource§fn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
Convert the handler into a
MakeService
which stores information
about the incoming connection and has no state. Read more