简体   繁体   English

用Java中的RxJava2编写后续的API请求

[英]Writing subsequent API requests with RxJava2 in Java

I need to write subsequent requests in my Android project. 我需要在我的Android项目中编写后续请求。 So first an API request is made and when the asynchronous response comes back, the response are used in the second request, and so on. 因此,首先发出一个API请求,然后当异步响应返回时,在第二个请求中使用该响应,依此类推。

I've been studying the RxJava2 library but I haven't comprehended fully yet. 我一直在研究RxJava2库,但尚未完全理解。 Furthermore, the RxJava code will be in an Interactor class, that will call functions that reside in a repository, so I don't want to write out code directly inside the RxJava2 code, but call functions from another class. 此外,RxJava代码将在Interactor类中,该类将调用驻留在存储库中的函数,因此我不想直接在RxJava2代码内部写出代码,而是从另一个类中调用函数。 A GitHub repo that cover these areas would be very useful for me. 涵盖这些领域的GitHub存储库对我来说非常有用。

The flatMap operator is a canonical way for specifying continuations that depend on the result(s) of a previous source(s): flatMap运算符是一种规范的方式,用于指定依赖于先前源结果的延续:

retrofitAPI.getData(params)
.flatMap(data -> 
     retrofitAPI.getMoreData(data)
     .flatMap(moreData -> retrofitAPI.getEvenMoreData(data, moreData))
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM