Skip to content

[General FE] Build your HttpClient using window.fetch #57

@reboottime

Description

@reboottime

Overview

This article presents the use cases of an HTTP client and provides a solution for customizing a http client util utilizing window.fetch.

Requirements Analysis

  1. In certain scenarios, a single page application might utilize multiple API service resources, necessitating the customization of each request group with its distinct API base URL.
  2. Learning from the popular http client solution, axios.js, a http client needs to offer http request methods directly (such as DELETE, GET, PATCH, PUT, or POST). It would be highly beneficial if the HTTP client utility could directly expose these methods for ease of use. For example
httpClientInstance.get
httpClientInstance.post

HttpClient.get
HttpClient.post
  1. Support for retrying a failed request, ensuring that the system can automatically attempt the request again in case of failure
  2. Support aborting a request when necessary, for example, when a component is unmounted then corresponding request needs to be cancelled.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions