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
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl 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
sourceimpl<'de> Deserialize<'de> for HttpResponse
impl<'de> Deserialize<'de> for HttpResponse
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl PartialEq<HttpResponse> for HttpResponse
impl PartialEq<HttpResponse> for HttpResponse
sourcefn eq(&self, other: &HttpResponse) -> bool
fn eq(&self, other: &HttpResponse) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &HttpResponse) -> bool
fn ne(&self, other: &HttpResponse) -> bool
This method tests for !=
.
sourceimpl Serialize for HttpResponse
impl Serialize for HttpResponse
impl Eq for HttpResponse
impl StructuralEq for HttpResponse
impl StructuralPartialEq for HttpResponse
Auto Trait Implementations
impl RefUnwindSafe for HttpResponse
impl Send for HttpResponse
impl Sync for HttpResponse
impl Unpin for HttpResponse
impl UnwindSafe for HttpResponse
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more