mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Updating README
This commit is contained in:
@@ -283,6 +283,49 @@ axios.get('/user/12345')
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Config Defaults
|
||||||
|
|
||||||
|
You can specify config defaults that will be applied to every request.
|
||||||
|
|
||||||
|
### Global axios defaults
|
||||||
|
|
||||||
|
```js
|
||||||
|
axios.defaults.baseURL = 'https://api.example.com';
|
||||||
|
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
||||||
|
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||||
|
```
|
||||||
|
|
||||||
|
### Custom instance defaults
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Set config defaults when creating the instance
|
||||||
|
var instance = axios.create({
|
||||||
|
baseURL: 'https://api.example.com'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Alter defaults after instace has been created
|
||||||
|
instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Config order of precedence
|
||||||
|
|
||||||
|
Config will be merged with an order of precedence. The order is library defaults found in `lib/defaults.js`, then `defaults` property of the instance, and finally `config` argument for the request. The latter will take precedence over the former. Here's an example.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Create an instance using the config defaults provided by the library
|
||||||
|
// At this point the timeout config value is `0` as is the default for the library
|
||||||
|
var instance = axios.create();
|
||||||
|
|
||||||
|
// Override timeout default for the library
|
||||||
|
// Now all requests will wait 2.5 seconds before timing out
|
||||||
|
instance.defaults.timeout = 2500;
|
||||||
|
|
||||||
|
// Override timeout for this request as it's known to take a long time
|
||||||
|
instance.get('/longRequest', {
|
||||||
|
timeout: 5000
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## Interceptors
|
## Interceptors
|
||||||
|
|
||||||
You can intercept requests or responses before they are handled by `then` or `catch`.
|
You can intercept requests or responses before they are handled by `then` or `catch`.
|
||||||
|
|||||||
Reference in New Issue
Block a user