From 7843bfdfdabf086076d09562bf0e8aaeb8ac1fba Mon Sep 17 00:00:00 2001 From: Nick Uraltsev Date: Tue, 27 Oct 2015 23:44:14 -0700 Subject: [PATCH] Update README.md: instantiation --- README.md | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37cdc6d..3cba598 100644 --- a/README.md +++ b/README.md @@ -132,9 +132,34 @@ Helper functions for dealing with concurrent requests. ##### axios.all(iterable) ##### axios.spread(callback) +### Creating an instance + +You can create a new instance of axios with a custom config. + +##### axios.create([config]) + +```js +var instance = axios.create({ + timeout: 1000, + headers: {'X-Custom-Header': 'foobar'} +}); +``` + +### Instance methods + +The available instance methods are listed below. The specified config will be merged with the instance config. + +##### axios#request(config) +##### axios#get(url[, config]) +##### axios#delete(url[, config]) +##### axios#head(url[, config]) +##### axios#post(url[, data[, config]]) +##### axios#put(url[, data[, config]]) +##### axios#patch(url[, data[, config]]) + ## Request API -This is the available config options for making requests. Only the `url` is required. Requests will default to `GET` if `method` is not specified. +These are the available config options for making requests. Only the `url` is required. Requests will default to `GET` if `method` is not specified. ```js { @@ -269,6 +294,13 @@ var myInterceptor = axios.interceptors.request.use(function () {/*...*/}); axios.interceptors.request.eject(myInterceptor); ``` +You can add interceptors to a custom instance of axios. + +```js +var instance = axios.create(); +instance.interceptors.request.use(function () {/*...*/}); +``` + ## Handling Errors ```js