WrappedApi
This package wraps an Axios instance to provide consistent logging and other services.
API Documentation
WrappedApi
-
WrappedApi
-
static
-
.WrappedApi
- new exports.WrappedApi([options])
-
instance
-
.logger ⇒
object
-
.init([config]) ⇒
WrappedApi
-
.request([config]) ⇒
Promise.<WrappedApiResponse>
-
.get([url], [config]) ⇒
Promise.<WrappedApiResponse>
-
.delete([url], [config]) ⇒
Promise.<WrappedApiResponse>
-
.head([url], [config]) ⇒
Promise.<WrappedApiResponse>
-
.options([url], [config]) ⇒
Promise.<WrappedApiResponse>
-
.post([url], [data], [config]) ⇒
Promise.<WrappedApiResponse>
-
.put([url], [data], [config]) ⇒
Promise.<WrappedApiResponse>
-
.patch([url], [data], [config]) ⇒
Promise.<WrappedApiResponse>
-
.logger ⇒
-
static
-
.composeError(e) ⇒
WrappedApiError
-
.composeResponse(response) ⇒
WrappedApiResponse
-
.composeError(e) ⇒
-
.WrappedApi
-
inner
-
~WrappedApiError :
object
-
~WrappedApiResponse :
object
-
~WrappedApiError :
-
static
WrappedApi.WrappedApi
Wraps an Axios instance to provide standard logging & services.
Kind: static class of WrappedApi
-
.WrappedApi
- new exports.WrappedApi([options])
-
instance
-
.logger ⇒
object
-
.init([config]) ⇒
WrappedApi
-
.request([config]) ⇒
Promise.<WrappedApiResponse>
-
.get([url], [config]) ⇒
Promise.<WrappedApiResponse>
-
.delete([url], [config]) ⇒
Promise.<WrappedApiResponse>
-
.head([url], [config]) ⇒
Promise.<WrappedApiResponse>
-
.options([url], [config]) ⇒
Promise.<WrappedApiResponse>
-
.post([url], [data], [config]) ⇒
Promise.<WrappedApiResponse>
-
.put([url], [data], [config]) ⇒
Promise.<WrappedApiResponse>
-
.patch([url], [data], [config]) ⇒
Promise.<WrappedApiResponse>
-
.logger ⇒
-
static
-
.composeError(e) ⇒
WrappedApiError
-
.composeResponse(response) ⇒
WrappedApiResponse
-
.composeError(e) ⇒
new exports.WrappedApi([options])
WrappedApi constructor.
Param | Type | Description |
---|---|---|
[options] | object |
Options. |
[options.logger] | object |
Logger instance (default is global console object). Must have info, error & debug methods |
object
wrappedApi.logger ⇒ Get logger instance.
Kind: instance property of WrappedApi
Returns: object
- Logger instance.
WrappedApi
wrappedApi.init([config]) ⇒ Initialize Axios instance.
Kind: instance method of WrappedApi
Returns: WrappedApi
- WrappedApi instance for chaining.
Param | Type | Description |
---|---|---|
[config] | axios.AxiosRequestConfig |
Axios config object. |
Promise.<WrappedApiResponse>
wrappedApi.request([config]) ⇒ Send a generic request using the Axios instance.
Kind: instance method of WrappedApi
Returns: Promise.<WrappedApiResponse>
- WrappedApiResponse object.
Param | Type | Description |
---|---|---|
[config] | axios.AxiosRequestConfig |
Axios config object. |
Promise.<WrappedApiResponse>
wrappedApi.get([url], [config]) ⇒ Send a GET request using the Axios instance.
Kind: instance method of WrappedApi
Returns: Promise.<WrappedApiResponse>
- WrappedApiResponse object.
Param | Type | Description |
---|---|---|
[url] | string |
Request URL. |
[config] | axios.AxiosRequestConfig |
Axios config object. |
Promise.<WrappedApiResponse>
wrappedApi.delete([url], [config]) ⇒ Send a DELETE request using the Axios instance.
Kind: instance method of WrappedApi
Returns: Promise.<WrappedApiResponse>
- WrappedApiResponse object.
Param | Type | Description |
---|---|---|
[url] | string |
Request URL. |
[config] | axios.AxiosRequestConfig |
Axios config object. |
Promise.<WrappedApiResponse>
wrappedApi.head([url], [config]) ⇒ Send a HEAD request using the Axios instance.
Kind: instance method of WrappedApi
Returns: Promise.<WrappedApiResponse>
- WrappedApiResponse object.
Param | Type | Description |
---|---|---|
[url] | string |
Request URL. |
[config] | axios.AxiosRequestConfig |
Axios config object. |
Promise.<WrappedApiResponse>
wrappedApi.options([url], [config]) ⇒ Send a OPTIONS request using the Axios instance.
Kind: instance method of WrappedApi
Returns: Promise.<WrappedApiResponse>
- WrappedApiResponse object.
Param | Type | Description |
---|---|---|
[url] | string |
Request URL. |
[config] | axios.AxiosRequestConfig |
Axios config object. |
Promise.<WrappedApiResponse>
wrappedApi.post([url], [data], [config]) ⇒ Send a POST request using the Axios instance.
Kind: instance method of WrappedApi
Returns: Promise.<WrappedApiResponse>
- WrappedApiResponse object.
Param | Type | Description |
---|---|---|
[url] | string |
Request URL. |
[data] | object |
Request body. |
[config] | axios.AxiosRequestConfig |
Axios config object. |
Promise.<WrappedApiResponse>
wrappedApi.put([url], [data], [config]) ⇒ Send a PUT request using the Axios instance.
Kind: instance method of WrappedApi
Returns: Promise.<WrappedApiResponse>
- WrappedApiResponse object.
Param | Type | Description |
---|---|---|
[url] | string |
Request URL. |
[data] | object |
Request body. |
[config] | axios.AxiosRequestConfig |
Axios config object. |
Promise.<WrappedApiResponse>
wrappedApi.patch([url], [data], [config]) ⇒ Send a PATCH request using the Axios instance.
Kind: instance method of WrappedApi
Returns: Promise.<WrappedApiResponse>
- WrappedApiResponse object.
Param | Type | Description |
---|---|---|
[url] | string |
Request URL. |
[data] | object |
Request body. |
[config] | axios.AxiosRequestConfig |
Axios config object. |
WrappedApiError
WrappedApi.composeError(e) ⇒ Compose Axios error.
Kind: static method of WrappedApi
Returns: WrappedApiError
- WrappedApiError object.
Param | Type | Description |
---|---|---|
e | axios.AxiosError |
Axios error object. |
WrappedApiResponse
WrappedApi.composeResponse(response) ⇒ Compose Axios response.
Kind: static method of WrappedApi
Returns: WrappedApiResponse
- WrappedApiResponse object.
Param | Type | Description |
---|---|---|
response | axios.AxiosResponse |
Axios response object. |
object
WrappedApi~WrappedApiError : WrappedApi error object.
Kind: inner typedef of WrappedApi
Properties
Name | Type | Description |
---|---|---|
[error] | string |
Axios error message. |
[response] | object |
Received HTTP response. |
[response.status] | number |
Response status code. |
[response.headers] | object |
Selected response headers. |
[response.data] | object |
Response body. |
[request] | object |
HTTP request body. |
object
WrappedApi~WrappedApiResponse : WrappedApi response object.
Kind: inner typedef of WrappedApi
Properties
Name | Type | Description |
---|---|---|
[response] | object |
Received HTTP response. |
[response.status] | number |
Response status code. |
[response.statusText] | string |
Response status text. |
[response.headers] | object |
Selected response headers. |
[response.data] | object |
Response body. |
See more great templates and other tools on my GitHub Profile!