@overlay.fun/kit
Version:
TypeScript SDK for overlay.fun API
50 lines • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RequestHandler = void 0;
const BASE_URLS = {
devnet: 'https://devnet.overlay.fun',
mainnet: 'https://mainnet.overlay.fun'
};
class RequestHandler {
constructor(config) {
this.config = config;
}
getConfig() {
return this.config;
}
getBaseUrl() {
return BASE_URLS[this.config.env];
}
getHeaders() {
return {
'Content-Type': 'application/json',
'api-key': this.config.api_key,
'auth-key': this.config.auth_key
};
}
async get(endpoint) {
const url = `${this.getBaseUrl()}${endpoint}`;
const response = await fetch(url, {
method: 'GET',
headers: this.getHeaders()
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
}
async post(endpoint, data) {
const url = `${this.getBaseUrl()}${endpoint}`;
const response = await fetch(url, {
method: 'POST',
headers: this.getHeaders(),
body: data ? JSON.stringify(data) : undefined
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
}
}
exports.RequestHandler = RequestHandler;
//# sourceMappingURL=request.js.map