Constructor
new ApiClient(httpClient, instanceConfig)
ApiClient constructor
| Name | Type | Description |
|---|---|---|
httpClient | Object | | Http client or axios instance |
instanceConfig | AxiosRequestConfig | | Config defaults for the instance |
- Source
Members
defaults
Returns default configuration
- Source
defaults
Set default configuration value
- Source
import axios from 'axios';
const apiClient = new ApiClient(axios);
apiClient.defaults.headers.common['X-Test'] = 'test';
api.defaults.baseURL = 'https://example.com';
api.defaults.timeout = 100;
console.log(api.defaults.headers.common['X-Test'])
test
console.log(api.defaults.baseURL)
https://example.com
console.log(api.defaults.timeout)
100interceptors
Interceptors getter
- Source
Methods
addRequestInterceptor(onFulfilled, onRejectedopt) → {Number}
Add a request interceptor
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
onFulfilled | function | Any status code that lie within the range of 2xx cause this function to trigger | ||
onRejected | function | <optional> | null | Any status codes that falls outside the range of 2xx cause this function to trigger |
- Source
An ID used to remove interceptor later
- Type:
- Number
addResponseInterceptor(onFulfilled, onRejectedopt) → {Number}
Add a response interceptor
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
onFulfilled | function | Any status code that lie within the range of 2xx cause this function to trigger | ||
onRejected | function | <optional> | null | Any status codes that falls outside the range of 2xx cause this function to trigger |
- Source
- An ID used to remove interceptor later
- Type:
- Number
delete(url, configopt) → {Promise.<AxiosResponse.<any>>}
Performs DELETE Request
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url | String | Request url Request url | ||
config | Object | <optional> | {} | Request config |
- Source
- Type:
- Promise.<AxiosResponse.<any>>
get(url, configopt) → {Promise.<AxiosResponse.<any>>}
Performs GET Request
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url | String | Request url Request url | ||
config | Object | <optional> | {} | Request config |
- Source
- Type:
- Promise.<AxiosResponse.<any>>
getUri(configopt) → {string}
Returns the URL for making request
| Name | Type | Attributes | Description |
|---|---|---|---|
config | Object | <optional> | The config specific for this request (merged with defaults) |
- Source
- Type:
- string
head(url, configopt) → {Promise.<AxiosResponse.<any>>}
Performs HEAD Request
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url | String | Request url Request url | ||
config | Object | <optional> | {} | Request config |
- Source
- Type:
- Promise.<AxiosResponse.<any>>
options(url, configopt) → {Promise.<AxiosResponse.<any>>}
Performs OPTIONS Request
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url | String | Request url Request url | ||
config | Object | <optional> | {} | Request config |
- Source
- Type:
- Promise.<AxiosResponse.<any>>
patch(url, dataopt, configopt) → {Promise.<AxiosResponse.<any>>}
Performs PATCH Request
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url | String | Request url | ||
data | string | | <optional> | null | The data to be sent as the request body. Browser only: FormData, File, Blob. Node only: Stream, Buffer. |
config | Object | <optional> | {} | Request config |
- Source
- Type:
- Promise.<AxiosResponse.<any>>
patchForm(url, dataopt, configopt) → {Promise.<axios.AxiosResponse.<any>>}
Performs PATCH Request with FormData
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url | String | Request url | ||
data | string | | <optional> | null | The data to be sent as the request body. Browser only: FormData, File, Blob. Node only: Stream, Buffer. |
config | Object | <optional> | {} | Request config |
- Source
- Type:
- Promise.<axios.AxiosResponse.<any>>
post(url, dataopt, configopt) → {Promise.<AxiosResponse.<any>>}
Performs POST Request
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url | String | Request url | ||
data | string | | <optional> | null | The data to be sent as the request body. Browser only: FormData, File, Blob. Node only: Stream, Buffer. |
config | Object | <optional> | {} | Request config |
- Source
- Type:
- Promise.<AxiosResponse.<any>>
postForm(url, dataopt, configopt) → {Promise.<axios.AxiosResponse.<any>>}
Performs POST Request with FormData
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url | String | Request url | ||
data | string | | <optional> | null | The data to be sent as the request body. Browser only: FormData, File, Blob. Node only: Stream, Buffer. |
config | Object | <optional> | {} | Request config |
- Source
- Type:
- Promise.<axios.AxiosResponse.<any>>
put(url, dataopt, configopt) → {Promise.<AxiosResponse.<any>>}
Performs PUT Request
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url | String | Request url | ||
data | string | | <optional> | null | The data to be sent as the request body. Browser only: FormData, File, Blob. Node only: Stream, Buffer. |
config | Object | <optional> | {} | Request config |
- Source
- Type:
- Promise.<AxiosResponse.<any>>
putForm(url, dataopt, configopt) → {Promise.<axios.AxiosResponse.<any>>}
Performs PUT Request with FormData
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url | String | Request url | ||
data | string | | <optional> | null | The data to be sent as the request body. Browser only: FormData, File, Blob. Node only: Stream, Buffer. |
config | Object | <optional> | {} | Request config |
- Source
- Type:
- Promise.<axios.AxiosResponse.<any>>
removeRequestInterceptor(id)
Remove a Request interceptor from the stack
| Name | Type | Description |
|---|---|---|
id | Number | The ID that was returned by |
- Source
removeResponseInterceptor(id)
Remove a Response interceptor from the stack
| Name | Type | Description |
|---|---|---|
id | Number | The ID that was returned by |
- Source
request(config) → {Promise.<AxiosResponse.<any>>}
Dispatch a request
| Name | Type | Description |
|---|---|---|
config | Object | The config specific for this request (merged with defaults) |
- Source
- Type:
- Promise.<AxiosResponse.<any>>