UNPKG

nowpayments-api-typescript

Version:
26 lines (21 loc) 718 B
import axios, { AxiosInstance, AxiosResponse } from 'axios'; import { API_BASE_URL, API_VERSION } from '../constants'; export default class ApiConnection { apiKey: string; api: AxiosInstance; constructor({ apiKey }: { apiKey: string }) { this.apiKey = apiKey; this.api = axios.create({ baseURL: `${API_BASE_URL}/${API_VERSION}`, timeout: 10000, headers: { 'x-api-key': apiKey }, validateStatus: () => true, }); } async get(url: string, params?: object): Promise<AxiosResponse<any>> { return await this.api.get(url, { params }); } async post(url: string, params?: object): Promise<AxiosResponse<any>> { return await this.api.post(url, { ...params }); } }