request-promise

Requests with request-promise pipe result (Large data)

╄→гoц情女王★ 提交于 2019-12-11 15:53:14
问题 I try to download some data from an external API. I would like to pipe the response of every request. The array including the request URLs looks like this : [ 'https://scihub.copernicus.eu/dhus/odata/v1/Products(\'d98b8730-846f-46d0-a816-5ae4db9f56a7\')/$value', 'https://scihub.copernicus.eu/dhus/odata/v1/Products(\'6edaeb16-3077-45d1-b3f0-fa2d5549f64a\')/$value', 'https://scihub.copernicus.eu/dhus/odata/v1/Products(\'333db2aa-c695-4753-8bd1-e64308af26e1\')/$value', 'https://scihub.copernicus

Using Async await in react component

筅森魡賤 提交于 2019-12-11 10:48:30
问题 So I've created a component that shoots off post requests with props that I provide. Although I'm familiar with Async await I for some reason can't seem to get this to return the actual value of the fulfilled promise and instead just get pending. I've tried wrapping with more functions as I understand the promise is not being resolved. I feel like I'm missing something. A sample of my code below export default class PostController extends React.Component { constructor(props) { super(props) }

Nodejs async / await with delay

北战南征 提交于 2019-12-11 05:59:45
问题 I have a problem with this code: var request = require('request-promise'); class Test{ constructor(){ } async Start(){ var response = await this.getResponse(); await console.log(response); } async getResponse(){ var options = { uri: "https://www.google.com" } var response = await request(options); setTimeout(function(){ return response; },1000); } } module.exports = Test; When I run the Start(), the console logs "undefined", but why is this? I know that I set a 1 second delay on the return,

Why is the Promise reject() in my jest.mock going to a then() rather than a catch()?

你离开我真会死。 提交于 2019-12-01 18:33:04
I have two files, getItemInfo.js to make API calls and getItemInfo.test.js which is the respective Jest test file. On the test file, I am mocking the http calling triggered by node module request-promise . The question is on the second code block, surrounded by ********* 's. Basically why is the reject() error still going to a then() block in the second unit test? // getItemInfo.js const rp = require('request-promise'); const getItemInfo = (id) => { const root = 'https://jsonplaceholder.typicode.com/posts/'; const requestOptions = { uri: `${root}/${id}`, method: 'GET', json: true } return rp

Node.js - Working with an API limit of 5 requests per second

强颜欢笑 提交于 2019-11-30 22:05:26
I've got a 'script' that does thousands of requests to a specific API. This API will only allow 5 requests per second (and probably it measures differently then me). To make the requests I'm using request-promise framework, and I've superseded the normal request-promise function with this: const request_promise = require('request-promise') function waitRetryPromise() { var count = 0 // keeps count of requests function rp(options) { const timedCall = (resolve) => setTimeout( ()=>resolve(rp(options)),1000) // recursive call count += 1 if (count % 3 == 0) { // recalls after a second on every