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.
Trait Implementations§
Auto Trait Implementations§
impl<T, E, VER> !Freeze for Request<T, E, VER>
impl<T, E, VER> !RefUnwindSafe for Request<T, E, VER>
impl<T, E, VER> Send for Request<T, E, VER>
impl<T, E, VER> Sync for Request<T, E, VER>
impl<T, E, VER> Unpin for Request<T, E, VER>
impl<T, E, VER> !UnwindSafe for Request<T, E, VER>
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more