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
sourceimpl 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
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
sourceimpl Clone for HttpResponse
impl Clone for HttpResponse
sourcefn clone(&self) -> HttpResponse
fn clone(&self) -> HttpResponse
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl Debug for HttpResponse
impl Debug for HttpResponse
sourceimpl Default for HttpResponse
impl Default for HttpResponse
sourcefn default() -> HttpResponse
fn default() -> HttpResponse
create default HttpResponse with status 200, empty body and empty header