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.
npm install --save ajax-fetch-esm
- 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.
// 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;
See CHANGELOG.
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.