@veterancrowd/wrapped-api
v0.0.11
Published
An Axios instance wrapped to provide consistent logging and other services.
Downloads
10
Readme
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>
- static
- .composeError(e) ⇒ WrappedApiError
- .composeResponse(response) ⇒ WrappedApiResponse
- .WrappedApi
- inner
- ~WrappedApiError : object
- ~WrappedApiResponse : object
- 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>
- static
- .composeError(e) ⇒ WrappedApiError
- .composeResponse(response) ⇒ WrappedApiResponse
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 |
wrappedApi.logger ⇒ object
Get logger instance.
Kind: instance property of WrappedApi
Returns: object - Logger instance.
wrappedApi.init([config]) ⇒ WrappedApi
Initialize Axios instance.
Kind: instance method of WrappedApi
Returns: WrappedApi - WrappedApi instance for chaining.
| Param | Type | Description | | --- | --- | --- | | [config] | axios.AxiosRequestConfig | Axios config object. |
wrappedApi.request([config]) ⇒ Promise.<WrappedApiResponse>
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. |
wrappedApi.get([url], [config]) ⇒ Promise.<WrappedApiResponse>
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. |
wrappedApi.delete([url], [config]) ⇒ Promise.<WrappedApiResponse>
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. |
wrappedApi.head([url], [config]) ⇒ Promise.<WrappedApiResponse>
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. |
wrappedApi.options([url], [config]) ⇒ Promise.<WrappedApiResponse>
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. |
wrappedApi.post([url], [data], [config]) ⇒ Promise.<WrappedApiResponse>
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. |
wrappedApi.put([url], [data], [config]) ⇒ Promise.<WrappedApiResponse>
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. |
wrappedApi.patch([url], [data], [config]) ⇒ Promise.<WrappedApiResponse>
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. |
WrappedApi.composeError(e) ⇒ WrappedApiError
Compose Axios error.
Kind: static method of WrappedApi
Returns: WrappedApiError - WrappedApiError object.
| Param | Type | Description | | --- | --- | --- | | e | axios.AxiosError | Axios error object. |
WrappedApi.composeResponse(response) ⇒ WrappedApiResponse
Compose Axios response.
Kind: static method of WrappedApi
Returns: WrappedApiResponse - WrappedApiResponse object.
| Param | Type | Description | | --- | --- | --- | | response | axios.AxiosResponse | Axios response object. |
WrappedApi~WrappedApiError : object
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. |
WrappedApi~WrappedApiResponse : object
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!