Struct surf_disco::client::Client

source ·
pub struct Client<E, VER: StaticVersionType> { /* private fields */ }
Expand description

A client of a Tide Disco application.

Implementations§

source§

impl<E: Error, VER: StaticVersionType> Client<E, VER>

source

pub fn new(base_url: Url) -> Self

Create a client and connect to the Tide Disco server at base_url.

source

pub fn builder(base_url: Url) -> ClientBuilder<E, VER>

Create a client with customization.

source

pub async fn connect(&self, timeout: Option<Duration>) -> bool

Connect to the server, retrying if the server is not running.

It is not necessary to call this function when creating a new client. The client will automatically connect when a request is made, if the server is available. However, this can be useful to wait for the server to come up, if the server may be offline when the client is created.

This function will make an HTTP GET request to the server’s /healthcheck endpoint, to test if the server is available. If this request succeeds, connect returns true. Otherwise, the client will continue retrying /healthcheck requests until timeout has elapsed (or forever, if timeout is None). If the timeout expires before a /healthcheck request succeeds, connect will return false.

source

pub async fn wait_for_health<H: DeserializeOwned + HealthCheck>( &self, healthy: impl Fn(&H) -> bool, timeout: Option<Duration> ) -> Option<H>

Connect to the server, retrying until the server is healthy.

This function is similar to connect. It will make requests to the /healthcheck endpoint until a request succeeds. However, it will then continue retrying until the response from /healthcheck satisfies the healthy predicate.

On success, returns the response from /healthcheck. On timeout, returns None.

source

pub fn get<T: DeserializeOwned>(&self, route: &str) -> Request<T, E, VER>

Build an HTTP GET request.

source

pub fn post<T: DeserializeOwned>(&self, route: &str) -> Request<T, E, VER>

Build an HTTP POST request.

source

pub async fn healthcheck<H: DeserializeOwned + HealthCheck>( &self ) -> Result<H, E>

Query the server’s healthcheck endpoint.

source

pub fn request<T: DeserializeOwned>( &self, method: Method, route: &str ) -> Request<T, E, VER>

Build an HTTP request with the specified method.

source

pub fn socket(&self, route: &str) -> SocketRequest<E, VER>

Build a streaming connection request.

§Panics

This will panic if a malformed URL is passed.

source

pub fn module<ModError: Error>( &self, prefix: &str ) -> Result<Client<ModError, VER>, ParseError>

Create a client for a sub-module of the connected application.

Trait Implementations§

source§

impl<E, VER: StaticVersionType> Clone for Client<E, VER>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<E, VER: StaticVersionType> Debug for Client<E, VER>

source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<E: Error, VER: StaticVersionType> From<ClientBuilder<E, VER>> for Client<E, VER>

source§

fn from(builder: ClientBuilder<E, VER>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<E, VER> Freeze for Client<E, VER>

§

impl<E, VER> !RefUnwindSafe for Client<E, VER>

§

impl<E, VER> Send for Client<E, VER>

§

impl<E, VER> Sync for Client<E, VER>

§

impl<E, VER> Unpin for Client<E, VER>

§

impl<E, VER> !UnwindSafe for Client<E, VER>

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.

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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