pub struct HttpResponse {
pub status_code: u16,
pub header: HeaderMap,
pub body: Vec<u8>,
}
Expand description
HttpResponse contains the actor’s response to return to the http client
Fields§
§status_code: u16
statusCode is a three-digit number, usually in the range 100-599, A value of 200 indicates success.
header: HeaderMap
Map of headers (string keys, list of values)
body: Vec<u8>
Body of response as a byte array. May be an empty array.
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn json<T>(payload: T, status_code: u16) -> Result<HttpResponse, RpcError>where
T: Serialize,
pub fn json<T>(payload: T, status_code: u16) -> Result<HttpResponse, RpcError>where
T: Serialize,
Creates a response with a given status code and serializes the given payload as JSON
pub fn ok<S: Into<Vec<u8>>>(response: S) -> HttpResponse
Sourcepub fn json_with_headers<T>(
payload: T,
status_code: u16,
headers: HashMap<String, Vec<String>>,
) -> Result<HttpResponse, RpcError>where
T: Serialize,
pub fn json_with_headers<T>(
payload: T,
status_code: u16,
headers: HashMap<String, Vec<String>>,
) -> Result<HttpResponse, RpcError>where
T: Serialize,
Creates a response with a given status code, JSON-serialized payload, and headers specified by the header argument. Automatically includes the appropriate Content-Type header
§Arguments
payload
- Any struct implementing the Serialize trait from serde/serde_jsonstatus_code
- A 16-bit unsigned integer representing the outbound HTTP status code, e.g. 200 for successful interactions, 404 for not found, etc..headers
- A std::collections::HashMap from a String to a Vec() of Strings. The Content-Type header is ignored, for Content-Type will always default to application/json
Sourcepub fn not_found() -> HttpResponse
pub fn not_found() -> HttpResponse
Handy shortcut for creating a 404/Not Found response
Sourcepub fn internal_server_error<T: ToString>(msg: T) -> HttpResponse
pub fn internal_server_error<T: ToString>(msg: T) -> HttpResponse
Useful shortcut for creating a 500/Internal Server Error response
Sourcepub fn bad_request<T: ToString>(msg: T) -> HttpResponse
pub fn bad_request<T: ToString>(msg: T) -> HttpResponse
Shortcut for creating a 400/Bad Request response
Trait Implementations§
Source§impl Clone for HttpResponse
impl Clone for HttpResponse
Source§fn clone(&self) -> HttpResponse
fn clone(&self) -> HttpResponse
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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
create default HttpResponse with status 200, empty body and empty header
Source§impl<'de> Deserialize<'de> for HttpResponse
impl<'de> Deserialize<'de> for HttpResponse
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for HttpResponse
impl PartialEq for HttpResponse
Source§impl Serialize for HttpResponse
impl Serialize for HttpResponse
impl Eq for HttpResponse
impl StructuralPartialEq for HttpResponse
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.