Loading homepage
Implement a fetch-based API client with chainable, reusable request builders. Configure shared headers, add query parameters and JSON bodies, and send requests with predictable response and error handling.
JavaScript and TypeScript use the same contract. Tests use deterministic fixtures; API tests do not call external services.
Input: createApiClient("https://api.example.test/v1").get("/users").query({ page: 2 }).send() Output: Fetches https://api.example.test/v1/users?page=2 with method GET.
Input: client.post("users").body({ name: "Ada" }).send() Output: Sends serialized JSON with a default JSON content type and returns parsed response JSON.
Input: const base = client.get("users"); const page2 = base.query({ page: 2 }) Output: base stays unchanged; page2 is independently configured.
Examples illustrate the function contract and expected behavior.