RequestBuilder

Struct RequestBuilder 

Source
pub struct RequestBuilder<S, B = Body> { /* private fields */ }
Available on crate feature client only.
Expand description

The builder for building a request.

Implementations§

Source§

impl<S> RequestBuilder<S>

Source

pub fn data<D>(self, data: D) -> Self
where D: TryInto<Body>, D::Error: Error + Send + Sync + 'static,

Set the request body.

Source

pub fn json<T>(self, json: &T) -> Self
where T: Serialize,

Available on crate feature json only.

Set the request body as json from object with Serialize.

Source

pub fn form<T>(self, form: &T) -> Self
where T: Serialize,

Available on crate feature form only.

Set the request body as form from object with Serialize.

Source§

impl<S, B> RequestBuilder<S, B>

Source

pub fn method(self, method: Method) -> Self

Set method for the request.

Source

pub fn method_ref(&self) -> &Method

Get a reference to method in the request.

Source

pub fn uri<U>(self, uri: U) -> Self
where U: TryInto<Uri>, U::Error: Into<BoxError>,

Set uri for building request.

The uri will be split into two parts scheme+host and path+query. The scheme and host can be empty and it will be resolved as the target address. The path and query must exist and they are used to build the request uri.

Note that only path and query will be set to the request uri. For setting the full uri, use full_uri instead.

Source

pub fn set_query<T>(self, query: &T) -> Self
where T: Serialize,

Available on crate feature query only.

Set query for the uri in request from object with Serialize.

Source

pub fn uri_ref(&self) -> &Uri

Get a reference to uri in the request.

Source

pub fn version(self, version: Version) -> Self

Set version of the HTTP request.

If it is not set, the request will use HTTP/2 if it is enabled and supported by default.

Source

pub fn version_ref(&self) -> Option<Version>

Get a reference to version in the request.

Source

pub fn header<K, V>(self, key: K, value: V) -> Self
where K: TryInto<HeaderName>, K::Error: Error + Send + Sync + 'static, V: TryInto<HeaderValue>, V::Error: Error + Send + Sync + 'static,

Insert a header into the request header map.

Source

pub fn headers(&self) -> &HeaderMap

Get a reference to headers in the request.

Source

pub fn headers_mut(&mut self) -> &mut HeaderMap

Get a mutable reference to headers in the request.

Source

pub fn address<A>(self, address: A) -> Self
where A: Into<Address>,

Set target address for the request.

Source

pub fn host<H>(self, host: H) -> Self
where H: Into<Cow<'static, str>>,

Set target host for the request.

It uses http with port 80 by default.

For setting scheme and port, use Self::with_scheme and Self::with_port after specifying host.

Source

pub fn with_scheme(self, scheme: Scheme) -> Self

Set scheme for target of the request.

Source

pub fn with_port(self, port: u16) -> Self

Set port for target address of this request.

Source

pub fn target_ref(&self) -> &Target

Get a reference to Target.

Source

pub fn target_mut(&mut self) -> &mut Target

Get a mutable reference to Target.

Source

pub fn body<B2>(self, body: B2) -> RequestBuilder<S, B2>

Set a request body.

Source

pub fn body_ref(&self) -> &B

Get a reference to body in the request.

Source

pub fn layer<L>(self, layer: L) -> RequestBuilder<L::Service, B>
where L: Layer<S>,

Add a new Layer to the front of request builder.

Note that the Layer generated Service should be a OneShotService.

Source

pub fn with_callopt( self, callopt: CallOpt, ) -> RequestBuilder<WithOptService<S, CallOpt>, B>

Apply a CallOpt to the request.

Source

pub async fn send<RespBody>(self) -> Result<Response<RespBody>>
where S: OneShotService<ClientContext, Request<B>, Response = Response<RespBody>, Error = ClientError> + Send + Sync + 'static, B: Send + 'static,

Send the request and get the response.

Auto Trait Implementations§

§

impl<S, B = Body> !Freeze for RequestBuilder<S, B>

§

impl<S, B = Body> !RefUnwindSafe for RequestBuilder<S, B>

§

impl<S, B> Send for RequestBuilder<S, B>
where S: Send, B: Send,

§

impl<S, B> Sync for RequestBuilder<S, B>
where S: Sync, B: Sync,

§

impl<S, B> Unpin for RequestBuilder<S, B>
where S: Unpin, B: Unpin,

§

impl<S, B = Body> !UnwindSafe for RequestBuilder<S, B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more