JSPM

promise-xhr

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q29727F
  • License MIT

Wrapper for the XHR package

Package Exports

  • promise-xhr

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (promise-xhr) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.