4.1.0 • Published 8 years ago

tiny-xhr v4.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

The library's aim is wrap AJAX into ES6 Promise and simplify some processes like converting data and setting proper content type headers, parsing response headers. "Tiny-Xhr" takes two arguments, first Object with request details and second it is specified by user and will be given back with response (see below)

Main features of "Tiny-Xhr":

  • converting data into the appropriate format
  • setting appropriate content-type headers
  • parsing response
  • parsing response headers

Library automatically sets appropriate headers and convert data to proper format. For simplicity, library has such content types:

  • form - multipart/form-data, convert data to "FormData"
  • url - application/x-www-form-urlencoded, data is just encoded
  • json - application/json, data is converted to JSON

Response is an Object with three properties.

  • response - it's just response data
  • headers - {Function} provide parsed headers
  • data - data that has been passed as second argument

var xhr = require('tiny-xhr');
var data = document.querySelector('form');

var options = {
                url: 'www',
                method: 'POST/GET',
                type: 'form/url/json',
                data: 'data',
                headers: {
                  "Authorization": "Basic " + btoa("login:pass")
                }
              };

xhr(options, 'second argument')
  .then(function(data) {
    // data.response = it's just response
    // data.headers() = parsed headers {Object}
    // data.data = 'second argument'
  })
  .catch(function(error) {
    // doSomethingWithError
  });
4.1.0

8 years ago

4.0.0

8 years ago

3.0.0

8 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago