Skip to content

Instantly share code, notes, and snippets.

@Tetsuya-Minase
Last active June 27, 2019 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tetsuya-Minase/b50c74f36248978622972e2f4ffd3694 to your computer and use it in GitHub Desktop.
Save Tetsuya-Minase/b50c74f36248978622972e2f4ffd3694 to your computer and use it in GitHub Desktop.
description
import { get, post } from 'request';
import { RequestResponse } from '../../domain/model/request-response';
import { HttpRequest } from '../http-request';
import { injectable } from 'inversify';
@injectable()
export class HttpRequestImpl implements HttpRequest {
public get(url: string): Promise<RequestResponse> {
return new Promise<RequestResponse>((resolve, reject) => {
get(url, (e, response, body) => {
if (e) {
console.error('get error:', e);
reject({ error: e });
}
console.log('get success:', { response: response, body: body });
resolve({ response: response, body: body });
});
});
}
public post(param: any): Promise<RequestResponse> {
return new Promise<RequestResponse>((resolve, reject) => {
post(param, (e, response, body) => {
if (e) {
console.error('post error:', e);
reject({ error: e });
}
console.log('post success:', { response: response, body: body });
resolve({ response: response, body: body });
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment