Thesearetheavailableconfigoptionsformakingrequests.Onlythe`url` is required. Requests will default to `GET` if `method`isnotspecified.
```js
{
// `url` is the server URL that will be used for the request
url:'/user',
// `method` is the request method to be used when making the request
method:'get',// default
// `baseURL` will be prepended to `url` unless `url` is absolute.
// It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
// to methods of that instance.
baseURL:'https://some-domain.com/api/',
// `transformRequest` allows changes to the request data before it is sent to the server
// This is only applicable for request methods 'PUT', 'POST', 'PATCH' and 'DELETE'
// The last function in the array must return a string or an instance of Buffer, ArrayBuffer,
// FormData or Stream
// You may modify the headers object.
transformRequest:[function(data,headers){
// Do whatever you want to transform the data
returndata;
}],
// `transformResponse` allows changes to the response data to be made before
// it is passed to then/catch
transformResponse:[function(data){
// Do whatever you want to transform the data
returndata;
}],
// `headers` are custom headers to be sent
headers:{'X-Requested-With':'XMLHttpRequest'},
// `params` are the URL parameters to be sent with the request
// Must be a plain object or a URLSearchParams object
params:{
ID:12345
},
// `paramsSerializer` is an optional config in charge of serializing `params`
paramsSerializer:{
encode?:(param:string):string=>{/* Do custom ops here and return transformed string */},// custom encoder function; sends Key/Values in an iterative fashion
serialize?:(params:Record<string,any>,options?:ParamsSerializerOptions),// mimic pre 1.x behavior and send entire params object to a custom serializer func. Allows consumer to control how params are serialized.
indexes:false// array indexes format (null - no brackets, false (default) - empty brackets, true - brackets with indexes)
},
// `data` is the data to be sent as the request body
// Only applicable for request methods 'PUT', 'POST', 'DELETE , and 'PATCH'
// When no `transformRequest` is set, must be of one of the following types:
Whenusing`catch`, or passing a [rejection callback](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) as second parameter of `then`, the response will be available through the `error`objectasexplainedinthe[HandlingErrors](#handling-errors)section.
Configwillbemergedwithanorderofprecedence.Theorderislibrarydefaultsfoundin[lib/defaults.js](https://github.com/axios/axios/blob/master/lib/defaults/index.js#L28), 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
constinstance=axios.create();
// Override timeout default for the library
// Now all requests using this instance 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
Youcaninterceptrequestsorresponsesbeforetheyarehandledby`then` or `catch`.
Bydefault,axiosserializesJavaScriptobjectsto`JSON`. To send data in the [`application/x-www-form-urlencoded` format](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) instead, you can use the [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) API, which is [supported](http://www.caniuse.com/#feat=urlsearchparams) in the vast majority of browsers,and [ Node](https://nodejs.org/api/url.html#url_class_urlsearchparams) starting with v10 (released in 2018).
```js
constparams=newURLSearchParams({foo:'bar'});
params.append('extraparam','value');
axios.post('/foo',params);
```
###Querystring(Olderbrowsers)
Forcompatibilitywithveryoldbrowsers,thereisa[polyfill](https://github.com/WebReflection/url-search-params) available (make sure to polyfill the global environment).
>The`qs` library is preferable if you need to stringify nested objects, as the `querystring`methodhas[knownissues](https://github.com/nodejs/node-v0.x-archive/issues/1665) with that use case.
Untilaxiosreachesa`1.0` release, breaking changes will be released with a new minor version. For example `0.5.1`, and `0.5.4` will have the same API, but `0.6.0`willhavebreakingchanges.
axiosisheavilyinspiredbythe[$httpservice](https://docs.angularjs.org/api/ng/service/$http) provided in [AngularJS](https://angularjs.org/). Ultimately axios is an effort to provide a standalone `$http`-like service for use outside of AngularJS.