$HTTP From Angular Without Angular
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (response) {
console.log(response);
});
axios.get('/user')
.then(function (response) {
console.log(response);
})
.catch(function (response) {
console.log(response);
});
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (response) {
console.log(response);
});
axios.all([getOneThing(), getAnotherThing()])
.then(axios.spread(function(oneThingResponse, anotherThingResponse) {
//both responses are now available
}));
axios.interceptors.request.use(function (config) {
// Do something before request is sent
return config;
}, function (error) {
// Do something with request error
return Promise.reject(error);
});
A polyfill of the anticpated standard to simplify XMLHttpRequest
fetch('/users.html')
.then(function(response) {
return response.json()
}).then(function(json) {
//do something with json
})
var form = document.querySelector('form')
fetch('/users', {
method: 'post',
body: new FormData(form)
})
var input = document.querySelector('input[type="file"]')
var data = new FormData()
data.append('file', input.files[0])
fetch('/avatars', {
method: 'post',
body: data
})
fetch('/users')
.then(checkStatus)
.then(parseJSON)
.then(function(data) {
console.log('request succeeded with JSON response', data)
}).catch(function(error) {
console.log('request failed', error)
})
Homebrewed to our Needs
var options = {
async: true,
data: {},
error: function () {},
headers: [],
success: function () {}
};
client.get('http://youapiendpoint.com/whatever', options);