pub struct HttpResponse {
pub status: StatusCode,
pub headers: HeaderMap,
pub body: Option<Bytes>,
pub version: Version,
}Fields§
§status: StatusCodeThe HTTP status code of the response. This is a 3-digit integer that indicates the result of the request.
headers: HeaderMapThe headers of the HTTP response. Headers are key-value pairs that provide additional information about the response.
body: Option<Bytes>The body of the HTTP response.
This is the content that is sent back to the client.
The body is represented as a Bytes object for efficient handling of binary data.
But The Other Method like json(),body()can be used to get the body in different formats.
version: VersionThe HTTP version of the response.
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn status(&mut self, status: impl Into<StatusCode>)
pub fn status(&mut self, status: impl Into<StatusCode>)
Sets the StatusCode of the response. The StatusCode is a 3-digit integer that indicates the result of the request.
Sourcepub fn add_header(&mut self, key: &str, value: &str) -> Option<()>
pub fn add_header(&mut self, key: &str, value: &str) -> Option<()>
Adds a header to the response. The header is a key-value pair that provides additional information about the response.
pub fn send_text(&mut self, data: impl Into<String>)
pub fn send_bytes(&mut self, data: impl Into<Vec<u8>>)
pub fn send_html(&mut self, data: impl Into<String>)
pub fn send_json<T: Serialize>(&mut self, data: T)
Trait Implementations§
Source§impl Clone for HttpResponse
impl Clone for HttpResponse
Source§fn clone(&self) -> HttpResponse
fn clone(&self) -> HttpResponse
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HttpResponse
impl Debug for HttpResponse
Source§impl Default for HttpResponse
impl Default for HttpResponse
Source§fn default() -> HttpResponse
fn default() -> HttpResponse
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for HttpResponse
impl RefUnwindSafe for HttpResponse
impl Send for HttpResponse
impl Sync for HttpResponse
impl Unpin for HttpResponse
impl UnwindSafe for HttpResponse
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