0.3.5 • Published 2 years ago

k-xhr v0.3.5

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

k-xhr

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

Thanks to JSONPlaceholder for their open API which I used for testing.

Installation

npm install k-xhr

Quick Start

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

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
  });
0.3.5

2 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago