Expand description
§polyoxide-core
Core utilities and shared types for the polyoxide venue clients.
This crate provides the venue-neutral machinery every venue crate builds its HTTP clients on, and names no venue:
- Shared error types and error handling
- HTTP client configuration
- The transport seam,
HttpTransport, with theResponseit answers with and theTransportErrorit fails with, so the send loop names no HTTP library - Request builder utilities
- One send loop,
HttpClient::send, with the hooks a venue supplies (Throttle,RetryPolicy,Authenticator), and one health ping on it,HttpClient::health - Per-endpoint window quotas (
WindowQuotaTable, which builds aRateLimiter), token-cost buckets (CapacityBucket), theHoldtheir layers share, and the retry schedule (RetryConfig) - Optional OS keychain credential storage (behind the
keychainfeature)
§HTTP Client
Use HttpClientBuilder to create configured HTTP clients:
use polyoxide_core::HttpClientBuilder;
let client = HttpClientBuilder::new("https://api.example.com")
.timeout_ms(60_000)
.build()
.unwrap();§Error Handling
An unsuccessful response is ApiError::Response, carrying an
ErrorResponse: its status, headers, body, message and Retry-After.
A venue’s error type wraps ApiError, and its From<ApiError> is its
one decode, so a ? on core’s error anywhere reads the venue’s body.
Re-exports§
pub use capacity::CapacityBucket;pub use client::retry_after_header;pub use client::HttpClient;pub use client::HttpClientBuilder;pub use client::DEFAULT_POOL_SIZE;pub use client::DEFAULT_TIMEOUT_MS;pub use config::ClientConfig;pub use error::ApiError;pub use error::ErrorResponse;pub use health::Pong;pub use hold::Hold;pub use hooks::AttemptInfo;pub use hooks::Authenticator;pub use hooks::Charge;pub use hooks::Cost;pub use hooks::Decision;pub use hooks::DefaultRetryPolicy;pub use hooks::DynAuthenticator;pub use hooks::DynRetryPolicy;pub use hooks::DynThrottle;pub use hooks::LayerCharge;pub use hooks::LayerId;pub use hooks::NoThrottle;pub use hooks::Outcome;pub use hooks::Refused;pub use hooks::RequestMeta;pub use hooks::RequestParts;pub use hooks::ResponseMeta;pub use hooks::RetryPolicy;pub use hooks::Throttle;pub use rate_limit::BucketId;pub use rate_limit::EffectiveQuota;pub use rate_limit::Matching;pub use rate_limit::QuotaRow;pub use rate_limit::RateLimiter;pub use rate_limit::RetryConfig;pub use rate_limit::WindowQuotaTable;pub use request::QueryBuilder;pub use request::Request;pub use request::RequestError;pub use response::Response;pub use send::decode_json;pub use transport::ReqwestTransport;pub use transport::HttpRequest;pub use transport::HttpTransport;pub use transport::TransportError;pub use transport::TransportKind;pub use http;pub use reqwest;
Modules§
- capacity
CapacityBucket: a token bucket that holds a published burst, charges integer costs, and can be resized in place.- client
- config
- The transport settings every client builder holds.
- error
- health
- One health ping, on the send loop.
- hold
Hold: what the server said, shared by every layer of a throttle.- hooks
- The hooks a venue gives
HttpClient::send. - macros
- Macros for reducing boilerplate in API client implementations
- rate_
limit - Window quotas:
WindowQuotaTablebuilds aRateLimiter, which counts requests against the buckets a request’s method and path resolve to. - request
- response
- The response an
HttpTransporthands the send loop: an owned head and a lazy body. - send
HttpClient::send: core’s one send loop.- transport
- The seam between the send loop and the network.
Macros§
- client_
config_ setters - Generates a client builder’s transport setters over a
ClientConfigfield:base_url,timeout_ms,pool_size,with_retry_config,max_concurrent,runtimeandhttp_transport. - namespaces
- Generates a client’s namespace accessors: each clones the listed client fields into the same-named fields of its namespace struct.
- query_
setters - Generates a request builder’s query-parameter setters.
Functions§
- csv
- Comma-joins a multi-value query parameter;
Nonewhen the joined value is empty, so the parameter is omitted rather than sent empty. - truncate_
for_ log - Truncate a string for safe inclusion in log output.