title: Angular - Multiple conditional http requests
body: <p>I'm struggling a bit with coming up with a good solution for doing multiple http requests, based on the result of each of them. So far, I've been doing good with switchMap, as long as it's only 2 http requests. However, I've found out I need to perform 3, and I'm not sure how to do it with switchMap, or if there's a better solution for it.</p>
  
  <p>Basically, I will await a response, and if it comes back empty, I want to perform a 2nd request, and if that comes back empty, I want to perform a 3rd request.</p>
  
  <p>Let me try to give a simplified example of what I've gotten so far:</p>
  
  <pre><code>getData(): Observable&lt;number&gt; {
    const $subject = new Subject&lt;number&gt;();
  
    // loadData() takes in an id to specify what data to load
    service.loadData(1).pipe(
      switchMap(response =&gt; {
        if(response.length === 0) {
          return service.loadData(2);
        }
        else {
          return of(response);
        }
      }),
    ).subscribe(result =&gt; {
      $subject.next(result);
      $subject.complete();
    });
    return $subject.asObservable();
  
  </code></pre>
  
  <p>Now this works just fine, my issue is, that calling "loadData(2)", might also give back a response with length = 0, and in that case, I need to call loadData(3). </p>
  
  <p>I tried having another switchMap within the switchMap, but that didn't seem to work properly. So my question is, how would I be able to check the length of the response of loadData(2), and if it's 0, return service.loadData(3) ?</p>
  
  <p>Any help or tips are very welcome :)</p>