Skip to content

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.

License

Notifications You must be signed in to change notification settings

shallinta/ajax-fetch-esm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published