@commarket/rewardhub
v1.0.19
Published
To install the `@commarket/rewardhub` package, you can use npm or yarn:
Downloads
339
Readme
LoyaltyPlus Library
Installation
To install the @commarket/rewardhub
package, you can use npm or yarn:
Using npm
npm install @commarket/rewardhub
Using yarn
yarn add @commarket/rewardhub
Methods
configureAPI Method
The configureAPI
method is responsible for setting up and configuring an Axios instance to interact with a rewardhub API. This method handles the following tasks:
- Resolves the base URL for the API based on the provided environment.
- Sets a timeout for API requests.
- Configures request and response interceptors to log requests and responses.
- Handles token creation and renewal for authorization.
- Set default response language
Usage
Importing the Method
First, import the configureAPI
method and the rewardhubApi
instance from the module:
const apiOptions: ApiOptions = {
environment: EnvironmentEnum.PRD,
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
timeout: 60000, //DEFAULT 6000
verbose: false //DEFAULT false
language: 'pt-br' //DEFAULT en-us
};
configureAPI(apiOptions).then(() => { // Now you can use the configured rewardhubApi instance to make requests rewardhubApi.get('/endpoint') .then(response => { console.log(response.data); }) .catch(error => { console.error('API call error:', error); }); });
For more detailed documentation, please refer to the official [LoyaltyPlus Documentation](https://example.com/docs).