dotbit
Version:
A complete .bit SDK and utilities in TypeScript
37 lines • 1.14 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Networking = void 0;
const cross_fetch_1 = require("cross-fetch");
const DotbitError_1 = require("../errors/DotbitError");
class Networking {
constructor(baseUri) {
this.baseUri = baseUri;
}
throwOnError(res) {
if (res.err_no) {
throw new DotbitError_1.DotbitError(res.err_msg, res.err_no);
}
else {
return res.data;
}
}
get(path) {
return (0, cross_fetch_1.fetch)(this.baseUri + '/' + path, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
}
}).then(res => res.json()).then(this.throwOnError);
}
post(path, body) {
return (0, cross_fetch_1.fetch)(this.baseUri + '/' + path, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body)
}).then(res => res.json()).then(this.throwOnError);
}
}
exports.Networking = Networking;
//# sourceMappingURL=Networking.js.map
;