@thorbens/fetcher
v3.0.0-alpha.4
Published
Simple library which provides a wrapper for fetch.
Readme
Description
This package provides simple functional for performing http requests.
Responses can be retrieved as JSON or loaded into a Document (via JSDom).
Currently, two different fetchers are implemented (libs are peer dependencies):
NodeFetchFetcherusesnode-fetchas library.RequestFetcheruses defaultrequestas library.AxiosFetcheruses defaultaxiosas library.
Use
const fetcher = new RequestFetcher();
const response = await fetcher.fetch("http://google.com");
const body = response.body; // contains the raw response bodyPost example:
const fetcher = new RequestFetcher();
const options: FetchOptions = {
data: {
foo: `bar`,
},
method: Method.POST,
};
const response = await fetcher.fetch("https://httpbin.org/post", options);
const json = response.asJSON<HttpbinResponse>(); // contains the data returned as json object