Skip to main content

Crate fetch_kit

Crate fetch_kit 

Source
Expand description

Resilient HTTP client for Rust.

fetch_kit wraps reqwest with a native middleware stack and sensible defaults for retries, timeouts, and typed JSON helpers. Enable the circuit-breaker feature for automatic circuit-breaking on repeated failures.

§Middleware

The middleware::Middleware trait is the composition point. Its shape mirrors reqwest-middleware 0.5, so migrating an existing middleware is an import-path swap. Middleware wrap the transport in an onion; the middleware registered first is the outermost layer:

ClientBuilder::new(client)
    .with(AuthMiddleware)   // 1st registered → outermost
    .with(RetryMiddleware)  // 2nd registered
    .build();

request  →  Auth  →  Retry  →  transport
response ←  Auth  ←  Retry  ←  ╹

Bundled middleware (each behind a feature): middleware::RetryMiddleware (default-on, powered by the estate loop-retry backoff), middleware::CircuitBreakerMiddleware, middleware::ThrottleMiddleware, middleware::TimeoutMiddleware, and middleware::BaseUrlMiddleware.

§Built-ins are defaults; middleware are composition points

The ClientBuilder knobs configure the built-in stack: retries/retry_bounds shape the default retry middleware (feature retry), with_breaker inserts the default breaker, and base_url resolves paths eagerly. Custom middleware registered via ClientBuilder::with_middleware run outermost — wrapping the built-ins — so they observe the final outcome of the whole default stack. Post-build, Client::with_middleware appends middleware innermost on a built client.

Re-exports§

pub use error::FetchError;

Modules§

error
Error types.
middleware
Middleware implementations. Middleware: the core Middleware trait + ClientWithMiddleware chain runner, plus the bundled feature-gated implementations.

Structs§

Client
A resilient HTTP client with retry, timeout, and typed JSON support.
ClientBuilder
Builder for constructing a Client with custom configuration.
RequestBuilder
A wrapper around middleware::RequestBuilder that provides an ergonomic API and resolves the URL against the client’s base URL.
Response
A Response to a submitted Request.