import got from 'got'; import { OutgoingHttpHeaders } from 'http'; import * as _ from 'lodash'; export class HttpService { optionsFactory (body: any | null, headers: OutgoingHttpHeaders | null, timeout: number | null) { const options: any = {}; if (body) { options.json = { ...body }; } if (headers) { options.headers = headers; } if(_.isNumber(timeout)) { options.timeout = timeout; } return Object.getOwnPropertyNames(options).length === 0 ? null : options; } async get(url: string, options: any) { return await got.get(url, options); } async post(url: string, options: any) { return await got.post(url, options); } async put(url: string, options: any) { return await got.put(url, options); } async delete(url: string, options: any) { return await got.delete(url, options) } }