Core types, errors, and logic for type-safe HTTP clients
npm install @alt-stack/http-client-coreCore types, errors, and logic for type-safe HTTP clients.
``bash`
pnpm add @alt-stack/http-client-core zod
This package provides the foundation for building type-safe HTTP clients. It is not meant to be used directly - instead, use one of the binding packages:
- @alt-stack/http-client-fetch - Uses native fetch API@alt-stack/http-client-ky
- - Uses ky library
- Types: Request/response type extraction utilities
- Errors: ApiClientError, ValidationError, TimeoutError, UnexpectedApiClientErrorHttpExecutor
- ApiClient: Base client class that accepts an
- HttpExecutor: Interface for HTTP implementations
Implement the HttpExecutor interface:
`typescript
import { HttpExecutor, ExecuteRequest, ExecuteResponse } from "@alt-stack/http-client-core";
class MyExecutor implements HttpExecutor
async execute(request: ExecuteRequest): Promise
// Your implementation
return {
status: 200,
statusText: "OK",
data: parsedData,
raw: rawResponse,
};
}
}
`
Then create a client:
`typescript
import { ApiClient } from "@alt-stack/http-client-core";
const client = new ApiClient({
baseUrl: "https://api.example.com",
Request,
Response,
executor: new MyExecutor(),
});
``