mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Updating README
This commit is contained in:
@@ -1,6 +1,14 @@
|
|||||||
# axios [](https://travis-ci.org/mzabriskie/axios)
|
# axios [](https://travis-ci.org/mzabriskie/axios)
|
||||||
|
|
||||||
Lightweight Promise based XHR library
|
Promise based XHR library
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Making [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) supporting the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API
|
||||||
|
- Transforming request and response data
|
||||||
|
- Client side support for protecting against [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery)
|
||||||
|
- Specifying HTTP request headers
|
||||||
|
- Automatic transforms for JSON data
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
@@ -9,43 +17,43 @@ 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')
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
console.log(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', {
|
||||||
params: {
|
params: {
|
||||||
ID: 12345
|
ID: 12345
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
Performing a `POST` request
|
Performing a `POST` request
|
||||||
|
|
||||||
```js
|
```js
|
||||||
axios.post('/user', {
|
axios.post('/user', {
|
||||||
firstName: 'Fred',
|
firstName: 'Fred',
|
||||||
lastName: 'Flintstone'
|
lastName: 'Flintstone'
|
||||||
})
|
})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
Aliases are provided for success and error
|
Aliases are provided for success and error
|
||||||
|
|
||||||
```js
|
```js
|
||||||
axios.get('/user/12345')
|
axios.get('/user/12345')
|
||||||
.success(function () {
|
.success(function () {
|
||||||
console.log('user found');
|
console.log('user found');
|
||||||
})
|
})
|
||||||
.error(function () {
|
.error(function () {
|
||||||
console.log('error finding user');
|
console.log('error finding user');
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Request API
|
## Request API
|
||||||
@@ -56,8 +64,8 @@ Requests can be made by passing the relevant config to `axios`.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
axios({
|
axios({
|
||||||
url: '/user/12345',
|
method: 'get',
|
||||||
method: 'get'
|
url: '/user/12345'
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -135,19 +143,23 @@ When using the alias methods `url`, `method`, and `data` properties don't need t
|
|||||||
|
|
||||||
For either `success` or `error`, the following response will be provided.
|
For either `success` or `error`, the following response will be provided.
|
||||||
|
|
||||||
```js
|
```
|
||||||
{
|
axios.get('/user/12345')
|
||||||
// `data` is the response that was provided by the server
|
.success(function (
|
||||||
data: {/*...*/} ,
|
// `data` is the response that was provided by the server
|
||||||
|
data,
|
||||||
|
|
||||||
// `status` is the HTTP status code from the server response
|
// `status` is the HTTP status code from the server response
|
||||||
status: 200,
|
status,
|
||||||
|
|
||||||
// `headers` the headers that the server responded with
|
// `headers` the headers that the server responded with
|
||||||
headers: {/*...*/},
|
headers,
|
||||||
|
|
||||||
// `config` is the config that were provided to `axios` for the request
|
// `config` is the config that were provided to `axios` for the request
|
||||||
config: {/*...*/}
|
config
|
||||||
|
) {
|
||||||
|
// Do something with result
|
||||||
|
});
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -169,7 +181,7 @@ $ npm install axios
|
|||||||
|
|
||||||
Tested to work with >=IE8, Chrome, Firefox, Safari, and Opera.
|
Tested to work with >=IE8, Chrome, Firefox, Safari, and Opera.
|
||||||
|
|
||||||
## Attribution
|
## Thanks
|
||||||
|
|
||||||
axios is heavily inspired by Angular's $http service.
|
axios is heavily inspired by Angular's $http service.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user