rest - Delphi REST - 我如何知道何时检索到所有数据?
问题描述
在 Delphi Tokyo 中,我将一系列REST
组件(与 Delphi 一起提供的组件:RESTClient
、RESTRequest
、RESTResponse
、RESTAdapater
)捆绑在一起以检索REST
数据。
REST
正如服务器上定义的那样,调用将分页设置为某个值。
因此,在我的 Delphi 应用程序中,我必须反复更新RESTRequest
.
ResourceSuffix 添加 '?page=' 然后是页码。
由于各种 REST 服务可能有不同的分页,或者会有不同的结果行数。
我怎么知道我何时检索了所有数据?
当然,有一些更优雅的东西会一直尝试,直到检索到的行 = 0/一些错误。
解决方案
我找到了一个适合我的解决方案……我的数据来自 Oracle RDBMS,通过 ORDS 和 APEX。REST 内容(特别是 RAW 数据)中有一个用于下一个分页集的 URL。对于第一组数据,此 URL 引用位于 REST 数据流的末尾。对于每个后续数据集,URL 引用位于原始数据流的开头,因此您必须检查这两个位置。这是我正在使用的代码...
function IsMoreRESTDataAvailable(Content: String) : Boolean;
var
Test600 : String;
begin
// This routine takes the RESTResponse.Content, aka the raw REST data, and checks to see if there is a NEXT: string
// in either the end of the data (only available for the FIRST DATA set
// or the beginning of the data
result := False;
Test600 := RightStr(Content, 600);
If AnsiPos('"next":{"$ref":"https://<YOUR_SERVER_HERE>', Test600) <> 0 then
begin
result:= True;
Exit;
end;
// If we didn't find it at the end of the REST content, then check at the beginning
Test600 := LeftStr(Content, 600);
If AnsiPos('"next":{"$ref":"https://<YOUR_SERVER_HERE>', Test600) <> 0 then
begin
result:= True;
Exit;
end;
end;
推荐阅读
- html - 如何从 fontawesome 5 svg 开始评分?
- android - 隐藏Toast后是否可以完成测试?
- angular - 如何在组件之间共享来自 http 响应的数据?
- sql - Query to find rows with nearest date in future
- html - parttails html文件更改未显示在angularjs应用程序中
- d3.js - 使用 fitSize 函数无法正确显示特征
- javascript - 单击链接属性时强制在加载前重新加载页面
- hibernate - 如何在hibernate和jpa中加入uuid列?
- function - 如何基于数组检查 + if 语句返回值?
- python-3.x - Spyder:不同的结果取决于我使用 F5 还是 F9 运行代码