Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

A Fizzy client: one set of credentials on one origin. Most of the API is scoped to an account, reached with Client::for_account; what is not — sessions, identity, access tokens — hangs off the client itself.

Clients are cheap to clone and share their connection pool, credentials and cache.

Implementations§

Source§

impl Client

Source

pub fn builder(config: Config) -> ClientBuilder

A builder over a config.

Source

pub fn new( config: Config, provider: impl TokenProvider + 'static, ) -> Result<Client, Error>

Available on crate feature reqwest only.

A client with the default settings and a bearer token, on the HTTP client the SDK ships. Without the reqwest feature there is no such client, and a ClientBuilder with an HttpClient of the application’s own is the way in.

Source

pub fn config(&self) -> &Config

The config the client was built from.

Source

pub fn base_url(&self) -> &Url

The origin every call goes to.

Source

pub fn max_pages(&self) -> usize

How many pages a walk reads before stopping.

Source

pub fn for_account( &self, account_id: impl Into<String>, ) -> Result<AccountClient, Error>

A client scoped to one account. The id is checked for shape here — it goes into every path as one segment — and against Fizzy on the first call.

Source

pub fn for_configured_account(&self) -> Result<AccountClient, Error>

A client scoped to the account the config names, when it names one.

Source

pub fn scope(&self) -> Scope<'_>

The scope the account-free services send through.

Source

pub fn operation( &self, route: &'static Route, params: &[&dyn Display], ) -> Result<Operation, Error>

Starts a request for one of the modelled routes that needs no account. Generated service methods go through Scope::operation; reach for this directly only to add headers or query parameters they do not expose.

Source

pub fn request(&self, method: Method, path: impl Into<String>) -> Operation

Starts a request for a path the model does not cover. The path is relative to the base URL and gets the same credentials and retry treatment as a modelled one.

Source

pub async fn send<T: DeserializeOwned>( &self, operation: Operation, ) -> Result<T, Error>

Sends an operation and decodes its JSON body.

Source

pub async fn send_unit(&self, operation: Operation) -> Result<(), Error>

Sends an operation whose answer carries no body worth reading.

Source

pub async fn send_page<T: DeserializeOwned>( &self, operation: Operation, ) -> Result<Page<T>, Error>

Sends a paginated read and keeps the cursor Fizzy answered with.

Source

pub async fn execute(&self, operation: Operation) -> Result<Response, Error>

Sends an operation: asks the hooks whether it may run, applies credentials, retries transient failures under the operation’s policy, and answers a cached body on 304. Non-2xx statuses become errors.

Source§

impl Client

Source

pub fn access_tokens(&self) -> AccessTokensService<'_>

The AccessTokens operations that need no account.

Source

pub fn identity(&self) -> IdentityService<'_>

The Identity operations that need no account.

Source

pub fn sessions(&self) -> SessionsService<'_>

The Sessions operations that need no account.

Source§

impl Client

Source

pub async fn next_page<T: DeserializeOwned>( &self, page: &Page<T>, ) -> Result<Option<Page<T>>, Error>

Reads the page after the given one, or None when Fizzy named no next page. A Link header pointing off the Fizzy origin is refused rather than followed. The read announces itself as the operation the first page came from and is sent under the same retry policy, so a whole walk shows up as one thing and is retried as one.

Source

pub async fn each_page<T: DeserializeOwned>( &self, first: Page<T>, visit: impl FnMut(&Page<T>) -> bool, ) -> Result<(), Error>

Reads every page after the first, up to the client’s page limit, calling visit with each one. Stops early when visit answers false.

Source

pub fn pages<'a, T: DeserializeOwned + 'a>( &'a self, first: Page<T>, ) -> impl Stream<Item = Result<Page<T>, Error>> + 'a

The first page and every one after it, read lazily as the stream is polled, up to the client’s page limit. A page in hand is yielded before the next is fetched, so a consumer that stops early never pays for a page it did not read, and a page that fails to read ends the stream with its error after the ones before it.

Source

pub fn items<'a, T: DeserializeOwned + 'a>( &'a self, first: Page<Vec<T>>, ) -> impl Stream<Item = Result<T, Error>> + 'a

Every item on every page, read lazily as the stream is polled.

Source

pub async fn get_all(&self, path: &str) -> Result<Vec<Value>, Error>

Reads a paginated path to its end and hands back the items of every page as one list. Each page has to decode as a JSON array. Use this for the paths the model does not cover; a modelled read walks with Client::each_page or Client::pages, which keep the records typed.

Source

pub async fn get_all_with_limit( &self, path: &str, limit: usize, ) -> Result<Vec<Value>, Error>

Reads a paginated path until limit items are in hand, or to its end when limit is zero. The last page is trimmed to land on exactly limit.

Source§

impl Client

Source

pub async fn get(&self, path: &str) -> Result<Response, Error>

Reads a path.

Source

pub async fn get_with( &self, path: &str, options: &RequestOptions, ) -> Result<Response, Error>

Reads a path under options of the caller’s own.

Source

pub async fn post( &self, path: &str, body: &impl Serialize, ) -> Result<Response, Error>

Posts a JSON body. Sent once unless the options say the call is idempotent.

Source

pub async fn post_with( &self, path: &str, body: &impl Serialize, options: &RequestOptions, ) -> Result<Response, Error>

Posts a JSON body under options of the caller’s own.

Source

pub async fn put( &self, path: &str, body: &impl Serialize, ) -> Result<Response, Error>

Puts a JSON body.

Source

pub async fn put_with( &self, path: &str, body: &impl Serialize, options: &RequestOptions, ) -> Result<Response, Error>

Puts a JSON body under options of the caller’s own.

Source

pub async fn patch( &self, path: &str, body: &impl Serialize, ) -> Result<Response, Error>

Patches with a JSON body.

Source

pub async fn patch_with( &self, path: &str, body: &impl Serialize, options: &RequestOptions, ) -> Result<Response, Error>

Patches with a JSON body under options of the caller’s own.

Source

pub async fn delete(&self, path: &str) -> Result<Response, Error>

Deletes a path.

Source

pub async fn delete_with( &self, path: &str, options: &RequestOptions, ) -> Result<Response, Error>

Deletes a path under options of the caller’s own.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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