title: Chaining requests in Retrofit + RxJava
body: <p>I have 2 APIs that I want to make request to in sequence and store their data in SQLite.</p>
  
  <p>First I want to make request to API <code>A</code> and store its data in SQL table <code>a</code>. Then make request to API <code>B</code> and store its data in table <code>b</code> and some data in table <code>a_b</code>. The data stored in <code>a_b</code> is from request <code>B</code> alone.</p>
  
  <p>How can I do this using RxJava. I read somewhere about using flatMap for this, something like this</p>
  
  <pre><code>apiService.A()
      // store in DB here? How? maybe use map()?
      .flatMap(modelA -&gt; {
          // or maybe store modelA in DB here?
          return apiService.B().map(modelB -&gt; {
              storeInDB()l // store B here ?
              return modelB;
          });
      });
  </code></pre>
  
  <p>If I wasn't using lambda functions, this would look as ugly as normal nested calls. Is this a better way to do it?</p>