Struct surf_disco::request::Request
source · pub struct Request<T, E, VER: StaticVersionType> { /* private fields */ }Implementations§
source§impl<T: DeserializeOwned, E: Error, VER: StaticVersionType> Request<T, E, VER>
impl<T: DeserializeOwned, E: Error, VER: StaticVersionType> Request<T, E, VER>
sourcepub fn header(
self,
key: impl Into<HeaderName>,
values: impl ToHeaderValues
) -> Self
pub fn header( self, key: impl Into<HeaderName>, values: impl ToHeaderValues ) -> Self
Set a header on the request.
sourcepub fn body_json<B: Serialize>(self, body: &B) -> Result<Self, E>
pub fn body_json<B: Serialize>(self, body: &B) -> Result<Self, E>
Set the request body using JSON.
Body is serialized using serde_json and the Content-Type header is set to
application/json.
sourcepub fn body_binary<B: Serialize>(self, body: &B) -> Result<Self, E>
pub fn body_binary<B: Serialize>(self, body: &B) -> Result<Self, E>
Set the request body using [bincode].
Body is serialized using [bincode] and the Content-Type header is set to
application/octet-stream.
§Errors
Fails if body does not serialize successfully.
sourcepub async fn send(self) -> Result<T, E>
pub async fn send(self) -> Result<T, E>
Send the request and await a response from the server.
If the request succeeds (receives a response with StatusCode::Ok) the response body is
converted to a T, using a format determined by the Content-Type header of the request.
§Errors
If the client is unable to reach the server, or if the response body cannot be interpreted
as a T, an error message is created using catch_all and returned.
If the request completes but the response status code is not StatusCode::Ok, an error
message is constructed using the body of the response. If there is a body and it can be
converted to an E using the content type specified in the response’s Content-Type
header, that E will be returned directly. Otherwise, an error message is synthesized using
catch_all that includes human-readable information about the response.