tiny xhr
1.0.0
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":
Library automatically sets appropriate headers and convert data to proper format. For simplicity, library has such content types:
Response is an Object with three properties.
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
});