Getting Started
Learn how to use the @availity/api-axios package for communicating with our APIs
Installation
Install the package through npm
, yarn
, or your favorite package manager. You must also install axios
as well.
NPM
npm install @availity/api-axios axios
Yarn
yarn add @availity/api-axios axios
AvApi
AvApi
is the default export from @availity/api-axios
. It is a class that wraps axios.
Features
- Automatic polling of restful endpoints with timeouts
- Simple URI builder for API resources
- Life-cycle hooks into HTTP calls for GET, PUT, POST, and DELETE
Usage
import AvApi from '@availity/api-axios';
const api = new AvApi({ name: 'test' });
Options
http
The default http client used is axios
. You can pass an object to this parameter in order to override axios
.
config
axios config object that will be passed to each call.
Request Config
Listed below are the options we primarily use from the axios config
or ones we have added.
config.api
Default true
. When true
, the url is built out by joining path
, version
, and name
or just url
if no name is defined. The id
is also added when appropriate. When api
is false
, all calls just use url
. URL pattern: path/version/name
config.url
This is used for requests when config.api
is false or name
is undefined;
config.path
Used for url building when config.api
is true. URL pattern path/version/name
config.version
Default v1
. Used for url building when config.api
is true. URL pattern path/version/name
config.name
The name of the resource. Used for url building when api
is true. (path/version/name
)