2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-05 16:42:32 +03:00

Make axios instantiable

This commit is contained in:
Nick Uraltsev
2015-10-03 09:38:16 -07:00
parent 4f732e8caa
commit b10874fa67
5 changed files with 194 additions and 42 deletions
+63 -15
View File
@@ -4,11 +4,11 @@ import axios = require('axios');
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
console.log(response);
})
.catch(function (response) {
console.log(response);
});
console.log(response);
});
axios.get('/user', {
params: {
@@ -96,16 +96,64 @@ axios({
});
axios({
url: "hi",
headers: {'X-Requested-With': 'XMLHttpRequest'},
url: "hi",
headers: {'X-Requested-With': 'XMLHttpRequest'},
params: {
ID: 12345
},
data: {
firstName: 'Fred'
},
withCredentials: false, // default
responseType: 'json', // default
xsrfCookieName: 'XSRF-TOKEN', // default
xsrfHeaderName: 'X-XSRF-TOKEN' // default
});
var instance = axios.createNew();
axios.createNew({
transformRequest: (data) => {
return data.doSomething();
},
transformResponse: (data) => {
return data.doSomethingElse();
},
headers: {'X-Requested-With': 'XMLHttpRequest'},
timeout: 1000,
withCredentials: false, // default
responseType: 'json', // default
xsrfCookieName: 'XSRF-TOKEN', // default
xsrfHeaderName: 'X-XSRF-TOKEN' // default
});
instance.request({
method: 'get',
url: '/user/12345'
})
.then(function (response) {
console.log(response);
})
.catch(function (response) {
console.log(response);
});
instance.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (response) {
console.log(response);
});
instance.get('/user', {
params: {
ID: 12345
},
data: {
firstName: 'Fred'
},
withCredentials: false, // default
responseType: 'json', // default
xsrfCookieName: 'XSRF-TOKEN', // default
xsrfHeaderName: 'X-XSRF-TOKEN' // default
});
}
})
.then(function (response) {
console.log(response);
})
.catch(function (response) {
console.log(response);
});