promise-xhr

1.0.1 • Public • Published

Promise XHR (xdr)

This is a Promise XHR wrapper. Uses https://www.npmjs.com/package/xhr under the hood.

NOTE

For older browsers you need a promise polyfill. https://www.npmjs.com/package/promise-polyfill

Installation

$ npm i --save promise-xhr

Usage

const xhr = require('promise-xhr');
const api = 'https://api.github.com';
 
// Options available:
// https://www.npmjs.com/package/xhr#var-req--xhroptions-callback
const options = {};
 
// Basic get request
xhr(api)
    .then(res => console.log(res))
    .catch(err => console.error(err));
 
// With options
xhr(api, {
    method: 'POST',
    useXDR: true
})
    .then(res => console.log(res)
    .catch(err => console.error(err));
 
// Available methods: get, post, put, patch, del, head
xhr.get(api).then(console.log).catch(console.error);
xhr.post(api, options).then(console.log).catch(console.error);
 

XHR package docs

https://www.npmjs.com/package/xhr

Contribution

Contributions are appreciated.

License

MIT-licensed. See LICENSE.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    4
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    4
  • 1.0.0
    0

Package Sidebar

Install

npm i promise-xhr

Weekly Downloads

4

Version

1.0.1

License

MIT

Last publish

Collaborators

  • bjarneo