UNPKG

http-service-lib

Version:

Reusable Http Service and implementations

22 lines (21 loc) 700 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FetchHttpService = void 0; class FetchHttpService { parseRequestBody(request) { if (request.headers['Content-Type'] && request.headers['Content-Type'].includes('application/json')) return JSON.stringify(request.body); return request.body; } async parseResponseBody(response) { let body = {}; if (response.headers.get('Content-Type')?.includes('application/json')) { body = await response.json(); } else { body = await response.text(); } return body; } } exports.FetchHttpService = FetchHttpService;