# Client API ## `createClient(config)` Creates a `BaseHttpClient`. ```ts const client = createClient({ baseUrl: "https://api.example.com", }); ``` ## `BaseHttpClient` Use `BaseHttpClient` directly when building wrapper-specific classes. ```ts class MyApiClient extends BaseHttpClient { getUser(id: string) { return this.get(`/users/${id}`); } } ``` ## Methods | Method | Description | | --- | --- | | `request(path, options)` | Execute a request and return the parsed body. | | `requestWithResponse(path, options)` | Execute a request and return body, response, request context, and metadata. | | `get(path, options)` | GET request. | | `post(path, body, options)` | POST request. | | `put(path, body, options)` | PUT request. | | `patch(path, body, options)` | PATCH request. | | `delete(path, options)` | DELETE request. | | `head(path, options)` | HEAD request. | | `options(path, options)` | OPTIONS request. | | `graphql(path, options)` | GraphQL POST request returning `data`. | | `init()` | Initialize plugins. Called lazily before the first request. | | `dispose()` | Run plugin cleanup hooks. | ## Response Parsing Requests parse JSON automatically when the response content type is JSON and fall back to text for other bodies. Pass `responseType` to override that: ```ts await client.get("/robots.txt", { responseType: "text" }); await client.post("/games.pb", query, { responseType: "arrayBuffer", }); ``` ## `requestWithResponse(path, options)` Use `requestWithResponse` when you need more than just parsed data. Prefer `request` for normal API calls, and choose `requestWithResponse` for wrappers, instrumentation, caching decisions, or debugging where headers/status/request context matter. ```ts const result = await client.requestWithResponse("/movie/popular"); result.data; // Parsed response body result.response.status; // Raw status code result.response.headers.get("x-ratelimit-remaining"); // Header access result.request.url; // Final URL after query merge result.meta["cache.served"]; // Plugin-provided metadata ``` ## Cancellation Pass `signal` on any request option to cancel work. Built-in transport and timeout handling observe the signal, and queued requests inside `createRateLimitPlugin` are removed before acquisition when the signal aborts. Already-aborted signals reject before reaching the transport. ## `ApiResponse` Returned by `requestWithResponse`. ```ts interface ApiResponse { data: T; // Parsed body returned by the parser response: Response; // Native response object for headers/status request: RequestContext; // Request details (URL, method, headers) meta: Record; // Plugin metadata from the request pipeline } ```