# k-xhr

> Lightweight promisified XMLHttpRequest

Latest version **0.3.5** (published 2022-07-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install k-xhr
pnpm add k-xhr
yarn add k-xhr
bun add k-xhr
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.5 |
| Published | 2022-07-16 |
| First published | 2017-01-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.6.0 |
| Dependencies | 0 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Thomas Peng Li |
| Maintainers | tmspnn |
| Keywords | k-xhr, XMLHttpRequest |

## Links

- npm: https://www.npmjs.com/package/k-xhr
- Repository: https://github.com/tmspnn/k-xhr
- Homepage: https://github.com/tmspnn/k-xhr#readme
- Issues: https://github.com/tmspnn/k-xhr/issues
- npm.io page: https://npm.io/package/k-xhr

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.3.5 (latest) — 2022-07-16
- 0.3.4 — 2021-06-22
- 0.3.3 — 2021-05-28
- 0.3.2 — 2021-05-18
- 0.3.1 — 2021-04-26
- 0.3.0 — 2021-04-26
- 0.2.4 — 2019-08-30
- 0.2.3 — 2019-08-29
- 0.2.2 — 2018-07-31
- 0.2.1 — 2018-06-28
- 0.2.0 — 2018-06-26
- 0.1.2 — 2017-01-23
- 0.1.1 — 2017-01-23
- 0.1.0 — 2017-01-17

## README

# k-xhr

Lightweight XMLHttpRequest, **0.2KB** gzipped, Promise compatible, **No dependencies**, IE11+.

Thanks to [JSONPlaceholder](https://jsonplaceholder.typicode.com/) for their open API which I used for testing.

## Installation

```
npm install k-xhr
```

## Quick Start

```javascript
import kxhr from "k-xhr";

const data = { id: 1, data: "Testing string" };

kxhr("https://jsonplaceholder.typicode.com/posts", "post", JSON.stringify(data), {
  contentType: "application/json"
}).then((res) => {
  const json = JSON.parse(res);
  console.log(json.id);
  console.log(json.data);
});
```

## Sequential Catch

```javascript
let i = 0;

kxhr("https://jsonplaceholder.typicode.com/todos/1")
  .then(() => {
    ++i; // i = 1
    throw new Error("catch 1");
  })
  .catch((e) => {
    ++i; // i = 2
  })
  .then(() => {
    ++i; // i = 3
    throw new Error("catch 2");
  })
  .catch((e) => {
    ++i; // i = 4
  })
  .finally(() => {
    console.log(i); // 4
  });
```

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