https://github.com/shallinta/ajax-fetch-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.
https://github.com/shallinta/ajax-fetch-esm
ajax esm fetch fetchapi interceptor typescript vite vue3
Last synced: 4 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/shallinta/ajax-fetch-esm
- Owner: shallinta
- License: mit
- Created: 2020-05-26T08:29:11.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-03-26T19:04:27.000Z (over 3 years ago)
- Last Synced: 2025-02-27T21:10:26.475Z (5 months ago)
- Topics: ajax, esm, fetch, fetchapi, interceptor, typescript, vite, vue3
- Language: TypeScript
- Homepage:
- Size: 297 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# AjaxFetch (esm)
[](https://www.npmjs.org/package/ajax-fetch-esm)
[](https://www.npmjs.org/package/ajax-fetch-esm)
[](https://github.com/shallinta/ajax-fetch-esm/blob/master/LICENSE)
[](https://github.com/shallinta/ajax-fetch-esm/issues?q=is%3Aopen+is%3Aissue)
[](https://github.com/shallinta/ajax-fetch-esm/issues?q=is%3Aissue+is%3Aclosed)

[](https://github.com/shallinta/ajax-fetch-esm)[](https://www.npmjs.com/package/ajax-fetch-esm)
> An **esm** ajax module based on [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), with **interceptors**. This ajax module is for those environments which do not support CommonJS modules, such as [vite](https://github.com/vuejs/vite).
## Install
```sh
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](https://developer.mozilla.org/en-US/docs/Web/API/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
```js
// use singleton ajaxFetch instance
import ajaxFetch from 'ajax-fetch-esm';
// add url prefix
ajaxFetch.interceptors.request.use((config) => ({ ...config, baseURL: '/api' }));
``````js
// 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](CHANGELOG.md).
## 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.