简体   繁体   中英

Writing subsequent API requests with RxJava2 in Java

I need to write subsequent requests in my Android project. 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.

I've been studying the RxJava2 library but I haven't comprehended fully yet. 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. A GitHub repo that cover these areas would be very useful for me.

The flatMap operator is a canonical way for specifying continuations that depend on the result(s) of a previous source(s):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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