1.2.1 • Published 9 years ago

xhr-promise-redux v1.2.1

Weekly downloads
23
License
MIT
Repository
github
Last release
9 years ago

Originally forked from frikille/promised-xhr

XHR Promise

This module wraps XMLHttpRequest with in promise object. The promise implementation is Promises/A+ compliant and is provided by the promise.js Promise library.

Installation

Install via npm NPM version

$ npm install xhr-promise-redux

API

var xhr = require('xhr-promise-redux');

xhr.get(url, options)
xhr.post(url, options)
xhr.send(url, options)

Examples

  1. Sending a GET request

      xhr.get('/test-url', {
        data: {
          param: 'value'
        },
        headers: {
          'Header-name': 'Header value'
        },
        responseType: 'json'
      })
      .then(function (response) {
        console.log(`Success! The response JSON object: ${response.body}`);
      })
      .catch(function(response) {
        console.log(`Error! Response Status Code: ${response.statusCode}`)
      });
  2. Sending a POST request with JSON

      xhr.post('/test-url', {
        json: {
          param: 'value'
        },
        headers: {
          'Header-name': 'Header value'
        },
        responseType: 'json'
      })
      .then(function (response) {
        console.log(`Success! The response JSON object: ${response.body}`);
      })
      .catch(function(response) {
        console.log(`Error! Response Status Code: ${response.statusCode}`)
      });
  3. Sending a request with any method

      xhr.send('/test-url', {
        method: 'PUT',
        json: {
          param: 'value'
        },
        headers: {
          'Header-name': 'Header value'
        }
      })
      .then(function (response) {
        console.log(`Success! The response JSON object: ${response.body}`);
      })
      .catch(function(response) {
        console.log(`Error! Response Status Code: ${response.statusCode}`)
      });
1.2.1

9 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago