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>
impl<E: Error, VER: StaticVersionType> Client<E, VER>
sourcepub fn new(base_url: Url) -> Self
pub fn new(base_url: Url) -> Self
Create a client and connect to the Tide Disco server at base_url
.
sourcepub fn builder(base_url: Url) -> ClientBuilder<E, VER>
pub fn builder(base_url: Url) -> ClientBuilder<E, VER>
Create a client with customization.
sourcepub async fn connect(&self, timeout: Option<Duration>) -> bool
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
.
sourcepub async fn wait_for_health<H: DeserializeOwned + HealthCheck>(
&self,
healthy: impl Fn(&H) -> bool,
timeout: Option<Duration>
) -> Option<H>
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
.
sourcepub fn get<T: DeserializeOwned>(&self, route: &str) -> Request<T, E, VER>
pub fn get<T: DeserializeOwned>(&self, route: &str) -> Request<T, E, VER>
Build an HTTP GET
request.
sourcepub fn post<T: DeserializeOwned>(&self, route: &str) -> Request<T, E, VER>
pub fn post<T: DeserializeOwned>(&self, route: &str) -> Request<T, E, VER>
Build an HTTP POST
request.
sourcepub async fn healthcheck<H: DeserializeOwned + HealthCheck>(
&self
) -> Result<H, E>
pub async fn healthcheck<H: DeserializeOwned + HealthCheck>( &self ) -> Result<H, E>
Query the server’s healthcheck endpoint.
sourcepub fn request<T: DeserializeOwned>(
&self,
method: Method,
route: &str
) -> Request<T, E, VER>
pub fn request<T: DeserializeOwned>( &self, method: Method, route: &str ) -> Request<T, E, VER>
Build an HTTP request with the specified method.
sourcepub fn socket(&self, route: &str) -> SocketRequest<E, VER>
pub fn socket(&self, route: &str) -> SocketRequest<E, VER>
Trait Implementations§
source§impl<E: Error, VER: StaticVersionType> From<ClientBuilder<E, VER>> for Client<E, VER>
impl<E: Error, VER: StaticVersionType> From<ClientBuilder<E, VER>> for Client<E, VER>
source§fn from(builder: ClientBuilder<E, VER>) -> Self
fn from(builder: ClientBuilder<E, VER>) -> Self
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> 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