UNPKG

gosf-atk

Version:

shared atk api.

43 lines (37 loc) 1.05 kB
'use strict' ; const axios = require('axios') , qs = require('qs') , MemcachedModule = require('./MemcachedModule') ; module.exports = class HttpRequestModule extends MemcachedModule { constructor(){ super(); this.options = {} this.options.headers = { 'Content-Type' : 'application/x-www-form-urlencoded' } this.options.responseType = 'json' ; } addHeader( key , value ){ this.options.headers[key] = value ; } prepareHttp( url = '', datas = {}) { this.options.url = url ; this.options.data = qs.stringify( datas ) ; return this ; } async post(){ try{ this.options.method = 'post' ; return await axios( this.options ) ; }catch(e){ throw e ; } } async get(){ try{ return await axios.get( this.options.url ); }catch(e){ throw e ; } } }