@vepler/http-client
Version:
A flexible and extensible API service library for making HTTP requests with built-in authentication support for bearer tokens and API keys.
67 lines (66 loc) • 2.79 kB
TypeScript
import { AxiosInstance } from 'axios';
interface Options {
host: string;
timeout?: number;
logLevel: string;
headers?: Record<string, string>;
}
interface QueryParams {
token?: string;
apiKey?: string;
params?: Record<string, any>;
headers?: Record<string, string>;
}
type ResourceParams = Record<string, any>;
declare const ApiService: {
/**
* Create a new Axios instance with the provided options.
* @param options - Configuration options for the Axios instance.
* @returns An object containing the Axios client and CRUD methods.
*/
create(options: Options): {
client: AxiosInstance;
/**
* Send a GET request to the specified resource with optional query parameters.
* @param resource - The resource endpoint.
* @param params - The request parameters.
* @param queryParams - Additional query parameters and headers.
* @returns The response data.
*/
query(resource: string, params: ResourceParams, queryParams?: QueryParams): Promise<any>;
/**
* Send a GET request to the specified resource with an optional slug and query parameters.
* @param resource - The resource endpoint.
* @param slug - The resource identifier.
* @param queryParams - Additional query parameters and headers.
* @returns The response data.
*/
get(resource: string, slug?: string, queryParams?: QueryParams): Promise<any>;
/**
* Send a POST request to the specified resource with the provided data.
* @param resource - The resource endpoint.
* @param data - The request payload.
* @param queryParams - Additional query parameters and headers.
* @returns The response data.
*/
post(resource: string, data: any, queryParams?: QueryParams): Promise<any>;
/**
* Send a PUT request to the specified resource with the provided data.
* @param resource - The resource endpoint.
* @param data - The request payload.
* @param queryParams - Additional query parameters and headers.
* @returns The response data.
*/
put(resource: string, data: any, queryParams?: QueryParams): Promise<any>;
/**
* Send a DELETE request to the specified resource with an optional slug and query parameters.
* @param resource - The resource endpoint.
* @param slug - The resource identifier.
* @param queryParams - Additional query parameters and headers.
* @returns The response data.
*/
delete(resource: string, slug?: string, queryParams?: QueryParams): Promise<any>;
};
};
export * from './errors';
export default ApiService;