# xfetch-js

> > A extremely simple fetch extension for modern browsers inspired by [sindresorhus/ky](https://github.com/sindresorhus/ky). > > Which aims to be as small as possible and easy to use.

Latest version **0.6.0** (published 2023-06-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install xfetch-js
pnpm add xfetch-js
yarn add xfetch-js
bun add xfetch-js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2023-06-13 |
| First published | 2018-09-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=16.0.0 |
| Dependencies | 2 |
| Unpacked size | 18.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | maple3142 |
| Maintainers | maple3142 |
| Keywords | fetch, typings, modern, browser |

## Links

- npm: https://www.npmjs.com/package/xfetch-js
- Repository: https://github.com/maple3142/xfetch-js
- npm.io page: https://npm.io/package/xfetch-js

## Dependencies (2)

- [form-data](https://npm.io/package/form-data.md) ^4.0.0
- [node-fetch-commonjs](https://npm.io/package/node-fetch-commonjs.md) ^3.2.4

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.6.0 (latest) — 2023-06-13
- 0.5.0 — 2020-05-05
- 0.4.0 — 2019-10-08
- 0.3.4 — 2019-03-24
- 0.3.3 — 2019-03-24
- 0.3.2 — 2019-03-24
- 0.3.1 — 2019-03-24
- 0.3.0 — 2018-11-08
- 0.2.3 — 2018-10-29
- 0.2.2 — 2018-10-29
- 0.2.1 — 2018-10-10
- 0.2.0 — 2018-10-10
- 0.1.6 — 2018-09-22
- 0.1.5 — 2018-09-22
- 0.1.4 — 2018-09-14
- … 13 more at https://npm.io/package/xfetch-js/versions

## README

# xfetch-js

> A extremely simple fetch extension for modern browsers inspired by [sindresorhus/ky](https://github.com/sindresorhus/ky).
>
> Which aims to be as small as possible and easy to use.

[![Build Status](https://img.shields.io/travis/maple3142/xfetch-js.svg?style=flat-square)](https://travis-ci.org/maple3142/xfetch-js)
[![npm](https://img.shields.io/npm/v/xfetch-js.svg?style=flat-square)](https://www.npmjs.com/package/xfetch-js)
[![Type definition](https://img.shields.io/npm/types/xfetch-js.svg?style=flat-square)](https://github.com/maple3142/xfetch-js/blob/master/xfetch.base.d.ts)

## Examaple

```js
// get with query string
xf('https://postman-echo.com/get/', { qs: { foo: 'bar' } })
  .json()
  .then(console.log)

// post form
xf.post('https://postman-echo.com/post', { form: { foo: 'bar' } })
  .json()
  .then(console.log)

// post json with transforms
xf.post('https://postman-echo.com/post', { json: { foo: 'bar' } })
  .json(r => r.data)
  .then(console.log)

// extend, default baseURI in browser is document.baseURI
const xf2 = xf.extend({
  baseURI: 'https://postman-echo.com/'
})
xf2.get('/get').then(console.log)

// HTTPError
xf.get('https://postman-echo.com/404').catch(e => {
  assert(e instanceof xf.HTTPError)
  console.log(e.response)
})
```

## With node

```js
const xf = require('xfetch-js')
// This one will pollute global.URL and global.URLSearchParams, then return a xfetch client with node-fetch
// If you want a pure xfetch instance, use require('xfetch-js/xfetch')

xf('https://postman-echo.com/get/', { qs: { foo: 'bar' } })
  .json()
  .then(console.log)
```

## Main differences bewteen fetch and xfetch-js

- `credentials` is set to `same-origin` by default.
- Throws error when `response.ok` is not true
- Some useful methods to call, such as `get`,`post` and so on...
- Support some simple serialization, including `json`,`urlencoded` and `querystring`
- Support post transformation like `.json(r => r.body)`
- Create another instance with default options `xf.extend({})`
- `fetch(Request)` are not supported

## API

See [xfetch.base.d.ts](https://github.com/maple3142/xfetch-js/blob/master/xfetch.base.d.ts).

## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmaple3142%2Fxfetch-js.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmaple3142%2Fxfetch-js?ref=badge_large)

---
_Source: https://npm.io/package/xfetch-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
