Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xhr-promise-redux

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xhr-promise-redux

XMLHttpRequest implementation wrapped in a promise.js Promise object

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
194
decreased by-21.14%
Maintainers
1
Weekly downloads
 
Created
Source

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}`)
  });
  1. 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}`)
  });
  1. 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}`)
  });

Keywords

FAQs

Package last updated on 05 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc