2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00

Updating README

This commit is contained in:
Matt Zabriskie
2014-08-29 14:42:17 -06:00
parent 5e6e269b54
commit 1c35eaadc0
+23 -14
View File
@@ -9,12 +9,9 @@ Performing a `GET` request
```js ```js
// Make a request for a user with a given ID // Make a request for a user with a given ID
axios.get('/user?ID=12345') axios.get('/user?ID=12345')
.success(function (response) { .then(function (response) {
console.log(response); console.log(response);
}) })
.error(function (response) {
console.log(response);
});
// Optionally the request above could also be done as // Optionally the request above could also be done as
axios.get('/user', { axios.get('/user', {
@@ -22,12 +19,9 @@ axios.get('/user', {
ID: 12345 ID: 12345
} }
}) })
.success(function (response) { .then(function (response) {
console.log(response); console.log(response);
}) })
.error(function (response) {
console.log(response);
});
``` ```
Performing a `POST` request Performing a `POST` request
@@ -37,11 +31,20 @@ axios.post('/user', {
firstName: 'Fred', firstName: 'Fred',
lastName: 'Flintstone' lastName: 'Flintstone'
}) })
.success(function (response) { .then(function (response) {
console.log(response); console.log(response);
}) })
.error(function (response) { ```
console.log(response);
Aliases are provided for success and error
```js
axios.get('/user/12345')
.success(function () {
console.log('user found');
})
.error(function () {
console.log('error finding user');
}); });
``` ```
@@ -114,11 +117,17 @@ When using the alias methods `url`, `method`, and `data` properties don't need t
// `withCredentials` indicates whether or not cross-site Access-Control requests // `withCredentials` indicates whether or not cross-site Access-Control requests
// should be made using credentials // should be made using credentials
withCredentials: true, withCredentials: false, // default
// `responseType` indicates the type of data that the server will responsd with // `responseType` indicates the type of data that the server will responsd with
// config are 'arraybuffer', 'blob', 'document', 'json', 'text' // config are 'arraybuffer', 'blob', 'document', 'json', 'text'
responseType: 'json' responseType: 'json', // default
// `xsrfCookieName` is the name of the cookie to use as a value for xsrf token
xsrfCookieName: 'XSRF-TOKEN', // default
// `xsrfHeaderName` is the name of the http header that carries the xsrf token value
xsrfHeaderName: 'X-XSRF-TOKEN' // default
} }
``` ```
@@ -137,7 +146,7 @@ For either `success` or `error`, the following response will be provided.
// `headers` the headers that the server responded with // `headers` the headers that the server responded with
headers: {/*...*/}, headers: {/*...*/},
// `config` are the config that were provided to `axios` for the request // `config` is the config that were provided to `axios` for the request
config: {/*...*/} config: {/*...*/}
} }
``` ```