ic-api-caller
v2.0.0
Published
Caller used to call internal and external APIs passing auth and refresh tokens on headers for authenticated endpoints
Downloads
5
Readme
IC-API-CALLER
its a simple library that focus on make API calls simpler. By this concept the instanced object will have some information passed down its constructor, which will be used to ensure that all calls from this instances will be done in the same domain, tha path however is informed in the method called.
For the implementation we have two kinds of methods parameters:
// POST, PUT parameters
{
path: string;
body: unknown;
}
// GET, DELETE parameters
{
path: string;
}
The path will be concatenated with the base url informed in the object creation to form the called url and the body will be foward on the call;
The constructor object should follow this interface:
{
base_url: string;
auth_token?: string;
refresh_tokens?: {
path: string;
body: unknown;
token: string;
base_url: string;
}
}
The base_url
defines the domain in which the instanced object will request informations, auth_token
will be added in the requests header to ensure that authetication is done properly (we only suport token bearer authentication at the moment), refresh_tokens
is composed by information needed to refresh the auth token if it expires. The path
and base_url
in the refresh_tokens
enseure that we can refresh tokens when needed even if the path or base url are different than the actual requests urls and paths, the token
property ensures that we can foward the refresh token to the called endpoints and the body ensures that the refresh token request sends the correct body when requesting token refresh.
The implementation should occour like the following:
import Api from 'api-caller';
const api = new Api(connection_info);
const result = api.get(get_parameters);