@shogun-sdk/money-legos
Version:
Shogun Money Legos: clients and types for quotes, memes, prices, balances, fees, validations, etc.
43 lines • 1.31 kB
JavaScript
import axios from 'axios';
import { handleApiError } from './errors.js';
export class HttpApi {
constructor(baseUrl, endpoint = '/', rateLimiter) {
Object.defineProperty(this, "client", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "endpoint", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "rateLimiter", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.endpoint = endpoint;
this.client = axios.create({
baseURL: baseUrl,
headers: {
'Content-Type': 'application/json',
},
});
this.rateLimiter = rateLimiter;
}
async makeRequest(payload, weight = 2, endpoint = this.endpoint) {
try {
await this.rateLimiter.waitForToken(weight);
const response = await this.client.post(endpoint, payload);
return response.data;
}
catch (error) {
handleApiError(error);
}
}
}
//# sourceMappingURL=httpApi.js.map