Promise based Ajax module for react/react-native apps.
npm i -S ajax-promise-es6
// default timeout is 60000ms
// url : {type: 'string'}
// body : {type: 'object'}
// headers: {type: 'object', optional: 'true'}
import Ajax from 'ajax-promise-es6'
Ajax.post(url, body, headers).then((res)=> {
console.log(res);
}).catch((err)=> {
console.log(err);
});
Ajax.get(url, body, headers).then((res)=> {
console.log(res);
}).catch((err)=> {
console.log(err);
});
Ajax.post(url,
{
foo: 'hello', // body data
bar: 'there'
},
{
'Cookie': 'foo=bar' // headers
}
).then((res)=> {
// use JSON.parse(res);
console.log(res);
}).catch((err)=>{
console.log(err);
});