Last active
June 27, 2019 14:14
-
-
Save Tetsuya-Minase/b50c74f36248978622972e2f4ffd3694 to your computer and use it in GitHub Desktop.
description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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