UNPKG

dotbit-sdk-allin

Version:

A complete .bit SDK and utilities in TypeScript

33 lines 977 B
import { fetch } from 'cross-fetch'; import { DotbitError } from '../errors/DotbitError'; export class Networking { constructor(baseUri) { this.baseUri = baseUri; } throwOnError(res) { if (res.err_no) { throw new DotbitError(res.err_msg, res.err_no); } else { return res.data; } } get(path) { return fetch(this.baseUri + '/' + path, { method: 'GET', headers: { 'Content-Type': 'application/json', } }).then(res => res.json()).then(this.throwOnError); } post(path, body) { return fetch(this.baseUri + '/' + path, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(body) }).then(res => res.json()).then(this.throwOnError); } } //# sourceMappingURL=Networking.js.map