我正在开发一个 Spring WebFlux 应用程序,并且我有一个 Web 适配器,用于调用我使用的外部 api 方法。其中一个 api 使用带有 rel="next" 的链接标头具有分页结果。我需要调用这个 api,直到下一个链接不存在,但我不确定如何实现这一点。以下是我目前正在使用的基本调用:
public Flux<ItemDto> getAllItems(){
return webClient.get() //The headers and base url for the api are defined in the constructor
.uri("/api/items?limit=200") //limit is the number of items returned with 200 being the maximum
.retrieve()
.bodyToFlux(Map.class)
.map(ItemConverter::mapValueToItemDto);//This is just a conversion method that handles mapping
}
我需要的是能够重复此调用,但添加一个请求参数,该参数基于具有“下一个”rel 值的链接标头的一部分。
我已经看到提到使用扩展或重复,但我不确定如何准确使用它们。我知道使用 exchange 是获取 clientResponse 所必需的,因此我可以获得标头。
这个问题可能相当模糊,所以如果需要,我可以提供任何澄清。
ABOUTYOU
相关分类