从node.js中的各种请求统一数据
在我在Node.js(初学者的位置)中的当前项目上,有一个可以查询的数据来源(Web API),但仅限于给定位置的一定数量的条目。不可能请求完整的记录集(例如1000个条目),您只能从偏移量中选择最多50个条目。
获取数据的功能如下:
let myResponseData = await client.getData({userId: myId, first: 50, after: cursor});
其中userId
是身份验证,首先
是我要请求的记录数(0-50),>
是光标之后,
响应看起来像这样:
{
"totalRecords": 1000,
"page_info": {
"has_next_page": true,
"end_cursor": "this is some random string"
},
"data": [
{
"id:" 1,
"name": "Name1"
},
{
"id:" 2,
"name": "Name2"
}
]
}
我当前获取所有数据的进度是,我已经构建了一个函数,该函数从这样的数据源中读取所有
let myResponseData = await client.getData({userId: myId});
let hasNextPage = myResponseData.page_info.next_page;
let cursor = myResponseData.page_info.cursor;
while(hasNextPage){
console.log('next...' + cursor);
myResponseData= await client.getData({ userId: myId, first: 50, after: cursor});
hasNextPage = myResponseData.page_info.next_page;
cursor = myResponseData.page_info.cursor;
myFunctionToJoinData(myResponseData); //Here i need help
}
页面下一个 +随机字符串。 我的目标是像请求中一样最终获得JSON数据对象,但是拥有所有查询的所有条目
如何实现?
On my current project in node.js (where I'm a beginner), there is a source of data that can be queried (WEB API) but is restricted to a certain amount of entries from a given position. It is not possible to request the full record set (eg. 1000 entries) you only can select a maximum of 50 Entries from an offset.
The function to get the data is as follow:
let myResponseData = await client.getData({userId: myId, first: 50, after: cursor});
where userId
is an authentication, first
is the number of records I want to request (0-50), and after
is the cursor
the response looks like this:
{
"totalRecords": 1000,
"page_info": {
"has_next_page": true,
"end_cursor": "this is some random string"
},
"data": [
{
"id:" 1,
"name": "Name1"
},
{
"id:" 2,
"name": "Name2"
}
]
}
My current progress in fetching all data is, that i've already constructed a function that reads all pages from the data source like this:
let myResponseData = await client.getData({userId: myId});
let hasNextPage = myResponseData.page_info.next_page;
let cursor = myResponseData.page_info.cursor;
while(hasNextPage){
console.log('next...' + cursor);
myResponseData= await client.getData({ userId: myId, first: 50, after: cursor});
hasNextPage = myResponseData.page_info.next_page;
cursor = myResponseData.page_info.cursor;
myFunctionToJoinData(myResponseData); //Here i need help
}
This works so far since the console logs the next + random string.
My goal is to end up with a json data object like in the request, but having all the entries from all queries
How can this be achieved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论