0.1.1 • Published 4 years ago

@fmtk/http-client v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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;
}
0.1.1

4 years ago

0.1.0

4 years ago