UNPKG

1.34 kBPlain TextView Raw
1import * as AWS from 'aws-sdk';
2import {IResponse, response} from './tools';
3
4AWS.config.update({region: 'us-east-1'}); // Virginia
5
6
7
8export class Http {
9
10 private request:any;
11
12 constructor() {
13 this.request = require("request");
14 }
15
16 /**
17 * Make http request.
18 *
19 * @param params
20 * @param api
21 */
22 public async post(body: {postData: any}, params: { url: string, headers: any }): Promise<IResponse> {
23 try {
24 // Build the post string from an object
25 let post_data = body.postData;
26
27 let tsevoresponse = '';
28 const respRequestHTTP = await new Promise<IResponse>((res, rej) => {
29 this.request.post({
30 "headers": params.headers,
31 "url": params.url,
32 "body": JSON.stringify(post_data)
33 }, async (error, resp, pres) => {
34 if (error) {
35 console.log(900, error);
36 rej(response(false, error));
37 }
38 tsevoresponse = await JSON.parse(pres);
39 res(response(true, null, tsevoresponse));
40 })
41 });
42 return respRequestHTTP;
43 } catch (error) {
44 return response(false, error);
45 }
46 }
47
48}
\No newline at end of file