1.1.3 • Published 4 years ago

ajax-fetch-esm v1.1.3

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

AjaxFetch (esm)

npm package npm download github license github issues open github issues closed github language top github stars

NPM

An esm ajax module based on Fetch API, with interceptors. This ajax module is for those environments which do not support CommonJS modules, such as vite.

Install

npm install --save ajax-fetch-esm

Features

  • Basicaly ajax functions, such as get, post, etc.
  • Esm support.
  • Typescript support.
  • Based on Fetch API.
  • No third-party dependencies.
  • Singleton and multiple instances support.
  • Interceptors for both request and response. Use it just like axios interceptors.
  • More axios-like api support.

Usage

// use singleton ajaxFetch instance
import ajaxFetch from 'ajax-fetch-esm';
// add url prefix
ajaxFetch.interceptors.request.use((config) => ({ ...config, baseURL: '/api' }));
// use specific instance
import { AjaxFetch } from 'ajax-fetch-esm';

const ajaxFetchInstance = AjaxFetch.of();

ajaxFetchInstance.interceptors.request.use((config) => ({ ...config, baseURL: '/api' }));

export default ajaxFetchInstance;

Recently updated

See CHANGELOG.

Contribute to this

If you'd like to perfect AjaxFetch and implement more axios-like api based on Fetch API, feel free contributing to this repository. I have no requirement for this, as long as it is correct. Looking forward to your PRs.