trade360-nodejs-sdk
Version:
LSports Trade360 SDK for Node.js
56 lines • 2.03 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AxiosService = void 0;
const axios_1 = __importDefault(require("axios"));
const _utilities_1 = require("../../../utilities");
/**
* Axios service instance for different API endpoints with
* varying request and response types. class with a generic
* type TRequest for the request body:
* a generic type TRequest which represents the type of the
* request body. and a response type TResponse and return
* a promise of that response type TResponse.
* @param TRequest Type of the request body
* @param TResponse Type of the response body
* @returns Promise with object of TResponse structure
*/
class AxiosService {
constructor(baseURL) {
this.configRequest = {
validateStatus: function (status) {
return status >= 200 && status < 300; // Resolve only if the status
// code is above then 200 and less then 300
},
transformResponse: [
function (data) {
if (typeof data === 'string') {
try {
return _utilities_1.IdSafeJsonParser.parse(data);
}
catch (e) {
return data;
}
}
return data;
},
],
};
this.axiosInstance = axios_1.default.create({
baseURL,
headers: {
'Content-Type': 'application/json',
},
});
}
async get(url) {
return this.axiosInstance.get(url, this.configRequest);
}
async post(url, body) {
return this.axiosInstance.post(url, body, this.configRequest);
}
}
exports.AxiosService = AxiosService;
//# sourceMappingURL=axios.service.js.map