UNPKG

@bsv/sdk

Version:

BSV Blockchain Software Development Kit

31 lines 949 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FetchHttpClient = void 0; /** * Adapter for Node Https module to be used as HttpClient */ class FetchHttpClient { constructor(fetch) { this.fetch = fetch; } async request(url, options) { const fetchOptions = { method: options.method, headers: options.headers, body: JSON.stringify(options.data) }; const res = await this.fetch(url, fetchOptions); const mediaType = res.headers.get('Content-Type'); const data = mediaType?.startsWith('application/json') ?? false ? await res.json() : await res.text(); return { ok: res.ok, status: res.status, statusText: res.statusText, data: data }; } } exports.FetchHttpClient = FetchHttpClient; //# sourceMappingURL=FetchHttpClient.js.map