5.1.0 • Published 1 year ago

paper-plane v5.1.0

Weekly downloads
7
License
MIT
Repository
github
Last release
1 year ago

paper-plane

Simple XHR and navigator.sendBeacon wrapper

Maybe fetch in a later version

No dependencies

Installation

npm install paper-plane

paper-plane is an ES module.

However, dist/paperplan.min.js is not (as browser support for ESM is not widespread), this file will create a PaperPlane object attached to the window (window.PaperPlane). This will likely change in the future.

Fetching data

GET Request

const headers = new Map();
const successCallback = function() {
    alert('GET call successful');
};

PaperPlane.get(
    '/endpoint',
    headers,
    successCallback
);

HEAD Request

const headers = new Map();
const successCallback = function() {
    alert('HEAD call successful');
};

PaperPlane.head(
    '/endpoint',
    headers,
    successCallback
);

Sending data

Sending data requires constructing a request payload or query string with one of the PaperPlane helper methods. The examples below construct a JSON payload via PaperPlane.makeJsonRequestData().

Constructing a payload from FormData is supported via PaperPlane.makeFormDataRequestData().

Constructing a payload from a Blob (or File, as a File is a Blob) is supported via PaperPlane.makeBlobRequestData().

Constructing a query string (to append to an endpoint) is supported via PaperPlane.makeUrlQueryString()

POST Request

const headers = new Map();
const successCallback = function() {
    alert('POST call successful');
};

PaperPlane.post(
    '/endpoint',
    PaperPlane.makeJsonRequestData({}, headers),
    successCallback
);

PUT Request

const headers = new Map();
const successCallback = function() {
    alert('PUT call successful');
};

PaperPlane.put(
    '/resource/id',
    PaperPlane.makeJsonRequestData({}, headers),
    successCallback
);

Beacon Request

Send an HTTP beacon request to server.

PaperPlane.postBeacon(
    '/analytics/view',
    PaperPlane.makeJsonRequestData({}, headers)
);

Removing data

DELETE Request

const headers = new Map();
const successCallback = function() {
    alert('DELETE call successful');
};

PaperPlane.delete(
    '/resources/id',
    PaperPlane.makeJsonRequestData({}, headers),
    successCallback
);
5.1.0

1 year ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.1.0

3 years ago

4.1.2

3 years ago

4.1.1

3 years ago

4.0.0

4 years ago

3.1.0

4 years ago

3.0.11

5 years ago

3.0.6

5 years ago

3.0.5

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.0

5 years ago

2.0.0

6 years ago

1.0.0-r2

7 years ago

1.0.0

7 years ago