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
impl Client
Sourcepub fn builder(config: Config) -> ClientBuilder
pub fn builder(config: Config) -> ClientBuilder
A builder over a config.
Sourcepub fn new(
config: Config,
provider: impl TokenProvider + 'static,
) -> Result<Client, Error>
Available on crate feature reqwest only.
pub fn new( config: Config, provider: impl TokenProvider + 'static, ) -> Result<Client, Error>
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.
Sourcepub fn for_account(
&self,
account_id: impl Into<String>,
) -> Result<AccountClient, Error>
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.
Sourcepub fn for_configured_account(&self) -> Result<AccountClient, Error>
pub fn for_configured_account(&self) -> Result<AccountClient, Error>
A client scoped to the account the config names, when it names one.
Sourcepub fn operation(
&self,
route: &'static Route,
params: &[&dyn Display],
) -> Result<Operation, Error>
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.
Sourcepub fn request(&self, method: Method, path: impl Into<String>) -> Operation
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.
Sourcepub async fn send<T: DeserializeOwned>(
&self,
operation: Operation,
) -> Result<T, Error>
pub async fn send<T: DeserializeOwned>( &self, operation: Operation, ) -> Result<T, Error>
Sends an operation and decodes its JSON body.
Sourcepub async fn send_unit(&self, operation: Operation) -> Result<(), Error>
pub async fn send_unit(&self, operation: Operation) -> Result<(), Error>
Sends an operation whose answer carries no body worth reading.
Source§impl Client
impl Client
Sourcepub fn access_tokens(&self) -> AccessTokensService<'_>
pub fn access_tokens(&self) -> AccessTokensService<'_>
The AccessTokens operations that need no account.
Sourcepub fn identity(&self) -> IdentityService<'_>
pub fn identity(&self) -> IdentityService<'_>
The Identity operations that need no account.
Sourcepub fn sessions(&self) -> SessionsService<'_>
pub fn sessions(&self) -> SessionsService<'_>
The Sessions operations that need no account.
Source§impl Client
impl Client
Sourcepub async fn next_page<T: DeserializeOwned>(
&self,
page: &Page<T>,
) -> Result<Option<Page<T>>, Error>
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.
Sourcepub async fn each_page<T: DeserializeOwned>(
&self,
first: Page<T>,
visit: impl FnMut(&Page<T>) -> bool,
) -> Result<(), Error>
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.
Sourcepub fn pages<'a, T: DeserializeOwned + 'a>(
&'a self,
first: Page<T>,
) -> impl Stream<Item = Result<Page<T>, Error>> + 'a
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.
Sourcepub fn items<'a, T: DeserializeOwned + 'a>(
&'a self,
first: Page<Vec<T>>,
) -> impl Stream<Item = Result<T, Error>> + 'a
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.
Sourcepub async fn get_all(&self, path: &str) -> Result<Vec<Value>, Error>
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§impl Client
impl Client
Sourcepub async fn get_with(
&self,
path: &str,
options: &RequestOptions,
) -> Result<Response, Error>
pub async fn get_with( &self, path: &str, options: &RequestOptions, ) -> Result<Response, Error>
Reads a path under options of the caller’s own.
Sourcepub async fn post(
&self,
path: &str,
body: &impl Serialize,
) -> Result<Response, Error>
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.
Sourcepub async fn post_with(
&self,
path: &str,
body: &impl Serialize,
options: &RequestOptions,
) -> Result<Response, Error>
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.
Sourcepub async fn put(
&self,
path: &str,
body: &impl Serialize,
) -> Result<Response, Error>
pub async fn put( &self, path: &str, body: &impl Serialize, ) -> Result<Response, Error>
Puts a JSON body.
Sourcepub async fn put_with(
&self,
path: &str,
body: &impl Serialize,
options: &RequestOptions,
) -> Result<Response, Error>
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.
Sourcepub async fn patch(
&self,
path: &str,
body: &impl Serialize,
) -> Result<Response, Error>
pub async fn patch( &self, path: &str, body: &impl Serialize, ) -> Result<Response, Error>
Patches with a JSON body.
Sourcepub async fn patch_with(
&self,
path: &str,
body: &impl Serialize,
options: &RequestOptions,
) -> Result<Response, Error>
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.
Sourcepub async fn delete_with(
&self,
path: &str,
options: &RequestOptions,
) -> Result<Response, Error>
pub async fn delete_with( &self, path: &str, options: &RequestOptions, ) -> Result<Response, Error>
Deletes a path under options of the caller’s own.