agentkit-http 0.5.1

HTTP client abstraction used across agentkit. Default reqwest-backed implementation behind an opt-out feature; BYO impls plug in via the HttpClient trait.
Documentation

agentkit-http

HTTP client abstraction used across agentkit. The HttpClient trait defines the single execute(HttpRequest) -> HttpResponse contract; the Http handle wraps any Arc<dyn HttpClient> and exposes a reqwest-style request builder (HttpRequestBuilder) for ergonomic call sites.

A default reqwest-backed implementation ships behind the reqwest-client feature, which is enabled by default. Disable it to compile trait-only when you want to bring your own backend:

agentkit-http = { version = "0.5", default-features = false }

A second optional feature, reqwest-middleware-client, layers reqwest-middleware on top for retry / tracing middleware stacks.

Quick start

use agentkit_http::{Http, StatusCode};

# async fn run() -> Result<(), Box<dyn std::error::Error>> {
let http = Http::new(reqwest::Client::new());

let response = http
    .post("https://example.test/echo")
    .bearer_auth("tok")
    .json(&serde_json::json!({ "name": "agentkit" }))
    .send()
    .await?;

assert_eq!(response.status(), StatusCode::OK);
let body: serde_json::Value = response.json().await?;
# Ok(())
# }

Http exposes the usual get / post / put / patch / delete / request constructors and is cheap to clone — it holds an Arc over the underlying client.

Bring your own client

Any type that implements HttpClient plugs in unchanged. This is the seam agentkit uses for stub clients in tests, custom TLS / proxy stacks, signing middleware, and non-reqwest backends:

use std::sync::Arc;
use agentkit_http::{Http, HttpClient, HttpError, HttpRequest, HttpResponse};
use async_trait::async_trait;

struct MyClient;

#[async_trait]
impl HttpClient for MyClient {
    async fn execute(&self, request: HttpRequest) -> Result<HttpResponse, HttpError> {
        // Drive `request.method`, `request.url`, `request.headers`,
        // `request.body` through your transport, then build an
        // `HttpResponse` from the streamed body.
        unimplemented!()
    }
}

let http = Http::from_arc(Arc::new(MyClient) as Arc<dyn HttpClient>);

Responses are surfaced as a streaming body (BodyStream), so SSE consumers can pull chunks incrementally rather than buffering the entire payload.