ajax-fetch-esm
v1.1.3
Published
An esm ajax module based on Fetch API, with interceptors. For those environments which do not support CommonJS, such as vite.
Downloads
6
Maintainers
Readme
AjaxFetch (esm)
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
- [x] Basicaly ajax functions, such as
get
,post
, etc. - [x] Esm support.
- [x] Typescript support.
- [x] Based on Fetch API.
- [x] No third-party dependencies.
- [x] Singleton and multiple instances support.
- [x] 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.