jattac.lib.apiaccessor
v0.0.8
Published
A library to help in accessing APIs in a structured way
Downloads
4
Readme
Jattac Computing User API Accessor Helper
This is a wrapper around axios, that allows you to do a one-off, low maintainance configuration for structured REST API calling. It includes methods for making HTTP POST and GET requests to specified endpoints, with optional parameters for customization. Additionally, it incorporates caching to optimize repeated GET requests.
Usage
Installation
npm i jattac.lib.apiaccessor
Configuration At the entry point of your application configure library as follows
import { EndpointConfigurationsRegistry, EndpointConfiguration } from 'jattac.lib.apiaccessor'; // Configure at least one endpoint const endpointConfig = EndpointConfiguration({ host: 'example.com', hostTrailingString: 'api/v1', //optional headersResolver: () => { const customHeaders = new Map<String, any>(); customHeaders.set('api-key', 'abcdef'); return customHeaders; }, // optional scheme: 'https', // optional, defaults to http port: 5113, // optional defaults to 80 }); EndpointConfigurationsRegistry.registerEndpointConfiguration('my-config', endpointConfig);
Extend ApiAccessorBase
import ApiAccessorBase from 'jattac.lib.apiaccessor';
class MyApiCaller extends ApiAccessorBase{
controller: string = "users";
endpointConfigurationName: "my-config"
}
### Properties
- `controller`: Abstract property representing the controller associated with the API.
- `endpointConfigurationName`: Abstract property specifying the name of the endpoint configuration.