Simple request/response api to wrap 'got' calls away

This commit is contained in:
shockrah 2021-01-28 17:54:49 -08:00
parent e2360834f1
commit 1b7092fd34
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,19 @@
const got = require('got')
const { Response } = require('./response.js')
/**
*
* @param {String} method GET POST DELETE
* @param {String} url full target url
* @param {Object} params Raw object of params to send
*
* @returns Response
*/
exports.Request = async function (method, url, params) {
try {
const result = await got(url, {json: params, method: method})
return new Response(result.statusCode, result.body, null)
} catch(err) {
return new Response(null, null, err)
}
}

View File

@ -0,0 +1,7 @@
exports.Response = class Response {
constructor(code, body, err) {
this.status_code = code
this.body = body
this.err = err
}
}