0.1.1 • Published 4 years ago
@fmtk/http-client v0.1.1
http-client
A collection of types and utility functions to enhance the fetch API.
Documentation
Basic interface
interface HttpClient {
(request: HttpClientRequest): Promise<HttpClientResponse>;
}
interface HttpClientRequest {
url: string;
method?: string;
headers?: HttpValueCollection;
body?: unknown;
}
interface HttpClientResponse {
status: number;
headers: HttpValueCollection;
body?: unknown;
}
Client composition
Compose a client with middleware to create a new, enhanced client.
const client = makeHttpClient(makeFetchClient(fetch), [
jsonClient(),
traceClient(console.log),
]);
The middleware interface is as follows:
interface HttpClientMiddleware {
(client: HttpClient): HttpClient;
}