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. ReqwestClientreads 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-supportfor a programmable fake client. UseBlockedHttpClientwhen 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-
anyhowerror value.
Structs§
- Async
Body - An HTTP body backed by empty state, in-memory bytes, or an asynchronous reader.
- Blocked
Http Client - An
HttpClientthat rejects every request withPermissionDenied. - Http
Client With Proxy - An
HttpClientthat may have a proxy. - Http
Client With Url - An
HttpClientthat has a base URL. - Method
- The Request Method (VERB)
- Request
- Represents an HTTP request.
- Reqwest
Client - A concrete
HttpClientbacked byreqwest. - Response
- Represents an HTTP response
- Status
Code - An HTTP status code (
status-codein RFC 9110 et al.). - Uri
- The URI component of a request.
- Url
- A parsed URL record.
Enums§
- Redirect
Policy - 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§
- Http
Client - Object-safe transport interface used by Kael application services.
- Http
Request Ext - Convenience methods for building requests accepted by
HttpClient.
Functions§
- read_
no_ proxy_ from_ env - Reads the first
NO_PROXYorno_proxyenvironment value. - read_
proxy_ from_ env - Reads a proxy URL from the first present conventional proxy environment variable.
Type Aliases§
- Result
Result<T, Error>