@bsv/sdk
Version:
BSV Blockchain Software Development Kit
28 lines • 813 B
JavaScript
/**
* Adapter for Node Https module to be used as HttpClient
*/
export class FetchHttpClient {
fetch;
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
};
}
}
//# sourceMappingURL=FetchHttpClient.js.map