https://github.com/un-ts/x-fetch
A simple but elegant `fetch` API wrapper, use `fetch` like a charm
https://github.com/un-ts/x-fetch
fetch fetch-api fetch-wrapper fetchapi fetcher ifetch
Last synced: 6 months ago
JSON representation
A simple but elegant `fetch` API wrapper, use `fetch` like a charm
- Host: GitHub
- URL: https://github.com/un-ts/x-fetch
- Owner: un-ts
- License: mit
- Created: 2023-11-07T04:31:00.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-01T01:48:28.000Z (8 months ago)
- Last Synced: 2025-07-07T14:42:54.318Z (6 months ago)
- Topics: fetch, fetch-api, fetch-wrapper, fetchapi, fetcher, ifetch
- Language: TypeScript
- Homepage: https://xfetch.vercel.app
- Size: 3.05 MB
- Stars: 5
- Watchers: 0
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# x-fetch
[](https://github.com/un-ts/x-fetch/actions/workflows/ci.yml?query=branch%3Amain)
[](https://codecov.io/gh/un-ts/x-fetch)
[](https://github.com/plantain-00/type-coverage)
[](https://coderabbit.ai)
[](https://www.npmjs.com/package/x-fetch)
[](https://github.com/un-ts/x-fetch/releases)
[](https://conventionalcommits.org)
[](https://renovatebot.com)
[](https://standardjs.com)
[](https://github.com/prettier/prettier)
[](https://github.com/changesets/changesets)
A simple but elegant `fetch` API wrapper with less than `850B` minified and brotlied, use `fetch` like a charm
## TOC
- [Usage](#usage)
- [Install](#install)
- [API](#api)
- [Sponsors and Backers](#sponsors-and-backers)
- [Sponsors](#sponsors)
- [Backers](#backers)
- [Changelog](#changelog)
- [License](#license)
## Usage
### Install
```sh
# npm
npm i x-fetch
# yarn
yarn add x-fetch
# pnpm
pnpm add x-fetch
# bun
bun add x-fetch
```
### API
```ts
import { ApiMethod, createXFetch, interceptors, xfetch } from 'x-fetch'
// plain url, GET method
await xfetch('url')
// with options, `method`, `body`, `query`, etc.
await xfetch('url', {
method: ApiMethod.POST, // or 'POST'
// plain object or array, or BodyInit
body: {},
// URLSearchParametersOptions
query: {
key: 'value',
},
// json: boolean, // whether auto stringify body to json, default true for plain object or array, otherwise false
// type: 'arrayBuffer' | 'blob' | 'json' | 'text' | null, `null` means plain `Response`
})
const interceptor: ApiInterceptor = (req, next) => {
// do something with req
const res = await next(req)
// do something with res
return res
}
// add interceptor
interceptors.use(interceptor)
// remove interceptor
interceptors.eject(interceptor)
// create a new isolated `xfetch` with its own `interceptors`
const { xfetch, interceptors } = createXFetch()
```
## Sponsors and Backers
[](https://github.com/sponsors/JounQin)
### Sponsors
| 1stG | RxTS | UnTS |
| ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unts) |
### Backers
| 1stG | RxTS | UnTS |
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unts) |
## Changelog
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
## License
[MIT][] © [JounQin][]@[1stG.me][]
[1stG.me]: https://www.1stG.me
[JounQin]: https://github.com/JounQin
[MIT]: http://opensource.org/licenses/MIT