pub struct Response { /* private fields */ }Expand description
HTTP Response builder that provides a fluent API for creating responses
Implementations§
Source§impl Response
impl Response
Sourcepub fn with_status(status: StatusCode) -> Self
pub fn with_status(status: StatusCode) -> Self
Create a response with a specific status code
Sourcepub fn internal_error() -> Self
pub fn internal_error() -> Self
Create a 500 Internal Server Error response
Sourcepub fn bad_request() -> Self
pub fn bad_request() -> Self
Create a 400 Bad Request response
Sourcepub fn no_content() -> Self
pub fn no_content() -> Self
Create a 204 No Content response
Create a 401 Unauthorized response
Sourcepub fn unprocessable_entity() -> Self
pub fn unprocessable_entity() -> Self
Create a 422 Unprocessable Entity response
Sourcepub fn too_many_requests() -> Self
pub fn too_many_requests() -> Self
Create a 429 Too Many Requests response
Sourcepub fn status(self, status: StatusCode) -> Self
pub fn status(self, status: StatusCode) -> Self
Set the status code
Sourcepub fn body_from_bytes(self, body: Vec<u8>) -> Self
pub fn body_from_bytes(self, body: Vec<u8>) -> Self
Set the response body from bytes
Sourcepub fn content_type(self, content_type: &str) -> Self
pub fn content_type(self, content_type: &str) -> Self
Set the Content-Type header
Sourcepub fn json<T: Serialize>(self, value: &T) -> Result<Self, Error>
pub fn json<T: Serialize>(self, value: &T) -> Result<Self, Error>
Set response as JSON and serialize the value (requires “json” feature)
Sourcepub fn redirect(status: StatusCode, location: &str) -> Self
pub fn redirect(status: StatusCode, location: &str) -> Self
Redirect to another URL
Sourcepub fn redirect_found(location: &str) -> Self
pub fn redirect_found(location: &str) -> Self
Redirect with 302 Found status
Sourcepub fn redirect_permanent(location: &str) -> Self
pub fn redirect_permanent(location: &str) -> Self
Redirect with 301 Moved Permanently status
Sourcepub fn status_code(&self) -> StatusCode
pub fn status_code(&self) -> StatusCode
Get the status code
Sourcepub fn status_code_mut(&mut self) -> &mut StatusCode
pub fn status_code_mut(&mut self) -> &mut StatusCode
Get a mutable reference to the status code
Sourcepub fn body_bytes(&self) -> &[u8] ⓘ
pub fn body_bytes(&self) -> &[u8] ⓘ
Get the body as bytes (alias for body_data)
Sourcepub fn into_hyper_response(self) -> Response<Full<Bytes>>
pub fn into_hyper_response(self) -> Response<Full<Bytes>>
Convert to hyper Response
Trait Implementations§
Source§impl From<StatusCode> for Response
impl From<StatusCode> for Response
Source§fn from(status: StatusCode) -> Self
fn from(status: StatusCode) -> Self
Converts to this type from the input type.
Source§impl IntoResponse for Response
impl IntoResponse for Response
fn into_response(self) -> 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