Why This Package Exists
packages/http-client gives Instructor a single HTTP API that works consistently across environments and drivers.
Primary goals:
- Stable request/response API across drivers (
curl,guzzle,symfony,laravel) - First-class streaming support for LLM responses
- Predictable middleware pipeline for cross-cutting behavior
- Concurrent request pooling with typed result handling
- Deterministic test workflows via mock and record/replay middleware
Core Building Blocks
HttpClient: entry point for request execution, middleware, and poolingHttpRequest: immutable request object (with*()returns a new request)PendingHttpResponse: deferred response execution (get()/stream())HttpRequestList/HttpResponseList: typed collections for poolingMiddlewareStack: immutable middleware composition
Docs Structure
Essentials
- Overview
- Getting Started
- Making Requests
- Handling Responses
- Streaming Responses
- Request Pooling
- Middleware
Extras
- Changing Client
- Changing Client Config
- Custom Clients
- Processing with Middleware
- Reliability Middleware
- Record and Replay
- Upgrade Guide (2.0)
Mental Model
Immutability Rules
with*() methods are immutable across core objects:
- Reassign clients:
$client = $client->withMiddleware(...) - Reassign requests:
$request = $request->withHeader(...) - Middleware stack operations return new stack instances
Recommended Scope
Use this package for:- LLM HTTP calls (sync or streaming)
- Request/response middleware customization
- Fan-out/fan-in workloads with pooled requests