Skip to content

frikille/promised-xhr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Promised XHR

A small client-side XHR abstraction with promises.

API

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

Examples

  1. Sending a GET request
  var XHR = require('promised-xhr');

  XHR.get('/test-url', {
    data: {
      param: 'value'
    },
    headers: {
      'Header-name': 'Header value'
    }
  })
  .then(function (response) {
    console.log('Success handler');
    console.log('The response JSON obejct', response.body);
  })
  .catch(function(response) {
    console.log('Error handler')
  });
  1. Sending a POST request
  var XHR = require('promised-xhr');

  XHR.post('/test-url', {
    data: {
      param: 'value'
    },
    headers: {
      'Header-name': 'Header value'
    }
  })
  .then(function (response) {
    console.log('Success handler');
    console.log('The response JSON obejct', response.body);
  })
  .catch(function(response) {
    console.log('Error handler')
  });
  1. Sending a request with any method
  var XHR = require('promised-xhr');

  XHR.send('/test-url', {
    method: 'PUT',
    data: {
      param: 'value'
    },
    headers: {
      'Header-name': 'Header value'
    }
  })
  .then(function (response) {
    console.log('Success handler');
    console.log('The response JSON obejct', response.body);
  })
  .catch(function(response) {
    console.log('Error handler')
  });

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published