sepia-search-motore-di-rice.../server/helpers/requests.ts

15 lines
431 B
TypeScript
Raw Normal View History

2020-02-13 11:49:03 +01:00
import * as Bluebird from 'bluebird'
import * as request from 'request'
2020-02-13 16:06:52 +01:00
function doRequest <T> (
2020-02-13 11:49:03 +01:00
requestOptions: request.CoreOptions & request.UriOptions
2020-02-13 16:06:52 +01:00
): Bluebird<{ response: request.RequestResponse, body: T }> {
return new Bluebird<{ response: request.RequestResponse, body: T }>((res, rej) => {
2020-02-13 11:49:03 +01:00
request(requestOptions, (err, response, body) => err ? rej(err) : res({ response, body }))
})
}
export {
doRequest
}