Skip to content

mharj/mharj-http-client

Repository files navigation

mharj-http-client

// initialize http client with 200ms delay on loading state change if progress is not supported (defaults 100ms)
const { fetch, addLoadingEventListener, addProgressEventListener } = HttpClient.getInstance({ delay: 200 });
addLoadingEventListener((isLoading: boolean) => {
  // do something for state boolean i.e. update redux state
});
addProgressEventListener((progress: IProgressPayload) => {
  // do something with download progress data {url: string; start?: Date; received?: number; size?: number; done: boolean}
});
export default fetch;

with logger (console, log4js)

// initialize http client
const { fetch } = HttpClient.getInstance({ logger: console });
export default fetch;

track Response body readable stream (if body stream reading is supported)

const res = await fetch("https://google.com");
watchResponseProgress(res, (progress) => console.log(progress));
const data = await res.text();

About

http client which tracks all loading and reports onLoading callback to get loading status changes

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages