smartapi-typescript
Version:
TypeScript library for Angel One SmartAPI broker API
54 lines (53 loc) • 2.13 kB
TypeScript
import { ApiResponse } from '../types';
/**
* Creates a configured axios instance for making HTTP requests
* @param baseURL The base URL for all requests
* @param headers The default headers to include with each request
* @returns Axios instance
*/
export declare const createHttpClient: (baseURL: string, headers?: Record<string, string>) => import("axios").AxiosInstance;
/**
* Handles API errors and formats error responses consistently
* According to SmartAPI documentation format:
* {
* "status": false,
* "message": "Error message",
* "errorcode": "ERROR_CODE",
* "data": null
* }
* @param error The error caught from an API request
* @returns Formatted API error response
*/
export declare const handleApiError: (error: any) => ApiResponse;
/**
* Makes an HTTP GET request to the specified endpoint
* @param url The endpoint URL
* @param headers Additional headers to include
* @param params Query parameters
* @returns Promise with the API response
*/
export declare const get: <T>(url: string, headers?: Record<string, string>, params?: any) => Promise<ApiResponse<T>>;
/**
* Makes an HTTP POST request to the specified endpoint
* @param url The endpoint URL
* @param data The request body data
* @param headers Additional headers to include
* @returns Promise with the API response
*/
export declare const post: <T>(url: string, data: any, headers?: Record<string, string>) => Promise<ApiResponse<T>>;
/**
* Makes an HTTP PUT request to the specified endpoint
* @param url The endpoint URL
* @param data The request body data
* @param headers Additional headers to include
* @returns Promise with the API response
*/
export declare const put: <T>(url: string, data: any, headers?: Record<string, string>) => Promise<ApiResponse<T>>;
/**
* Makes an HTTP DELETE request to the specified endpoint
* @param url The endpoint URL
* @param headers Additional headers to include
* @param params Query parameters
* @returns Promise with the API response
*/
export declare const del: <T>(url: string, headers?: Record<string, string>, params?: any) => Promise<ApiResponse<T>>;