Skip to main content

Crate kael_http_client

Crate kael_http_client 

Source
Expand description

§kael_http_client

Transport primitives and a ready-to-use HTTP client for Kael applications.

The crate keeps application code on the standard http request and response types behind an object-safe HttpClient trait. Applications can provide their own transport or use the included ReqwestClient. Proxy-aware and base-URL wrappers compose over either choice.

The reqwest feature is enabled by default. Transport implementations that only need Kael’s traits and standard HTTP types can disable default features to avoid pulling Reqwest and Tokio. The bundled adapter reuses pooled clients for the standard redirect modes, honors NO_PROXY, and applies 30-second connect and five-minute total request timeouts.

use kael_http_client::{AsyncBody, HttpClient, Request, ReqwestClient};

let client = ReqwestClient::user_agent("my-app/1.0")?;
let request = Request::get("https://example.com/status")
    .body(AsyncBody::empty())?;
let response = client.send(request).await?;

assert!(response.status().is_success());

§Design and limits

  • Redirects are disabled by default and can be enabled per request with HttpRequestExt.
  • ReqwestClient reads standard proxy environment variables and exposes the selected proxy through the transport trait.
  • The built-in adapter currently buffers request and response bodies with a 256 MiB hard limit. Custom transports can preserve streaming semantics when an application needs a different memory or backpressure policy.
  • Enable test-support for a programmable fake client. Use BlockedHttpClient when a subsystem must be prevented from reaching the network.

Part of the Kael native application framework. See the Kael documentation for framework-level guides.

§License

Licensed under the Apache License, Version 2.0. See LICENSE-APACHE.

Re-exports§

pub use http;

Macros§

anyhow
Construct an ad-hoc error from a string or existing non-anyhow error value.

Structs§

AsyncBody
An HTTP body backed by empty state, in-memory bytes, or an asynchronous reader.
BlockedHttpClient
An HttpClient that rejects every request with PermissionDenied.
HttpClientWithProxy
An HttpClient that may have a proxy.
HttpClientWithUrl
An HttpClient that has a base URL.
Method
The Request Method (VERB)
Request
Represents an HTTP request.
ReqwestClient
A concrete HttpClient backed by reqwest.
Response
Represents an HTTP response
StatusCode
An HTTP status code (status-code in RFC 9110 et al.).
Uri
The URI component of a request.
Url
A parsed URL record.

Enums§

RedirectPolicy
Controls how an HTTP request handles redirects.

Constants§

MAX_BUFFERED_HTTP_BODY_BYTES
Maximum body size buffered by the built-in native or browser transport.

Traits§

HttpClient
Object-safe transport interface used by Kael application services.
HttpRequestExt
Convenience methods for building requests accepted by HttpClient.

Functions§

read_no_proxy_from_env
Reads the first NO_PROXY or no_proxy environment value.
read_proxy_from_env
Reads a proxy URL from the first present conventional proxy environment variable.

Type Aliases§

Result
Result<T, Error>