title: Synchronous spring webflux call retaining the order of operation
body: <p>I have a simple use case and not sure how to do, as I'm new to spring webflux.</p>
  
  <p>I'm using <code>spring boot webflux starters</code>.
  I need to call 2 endpoints. Lets say <code>Endpoint1</code> and <code>Endpoint2</code>.</p>
  
  <p>Whenever <code>Endpoint1</code> is hit with a request, I should hit the <code>Endpoint2</code> first with the same request and use the response from the <code>Endpoint2</code> to enrich the original request and then do something further.
  <code>Endpoint1</code>'s request object needs to be enriched using the response from the <code>Endpoint2</code> before doing anything. How do I enforce this order using Spring webflux? In my case, the original request object is not enriched before it could be used further. Any help on this greatly appreciated!!!</p>
  
  <p>FYI - call to <code>Endpoint2</code> is done using <code>webclient</code></p>
  
  <h1>Just a pseudo code:</h1>
  
  <pre><code>public Mono&lt;Response1&gt; endpoint1(Request1 request1){
  
    Flux&lt;Response2&gt; reponse2 = webclient.getEndpoint2(request1); // Returns a Flux
  
    //use the above reponse2 to enrich the request1
  
    return webclient.getSomething(request1); //Returns Mono&lt;Response1&gt;
  
  }
  </code></pre>
  
  <h1>Actual code:</h1>
  
  <pre><code>
   public Mono&lt;ApplicationResponse&gt; save(ApplicationRequest request) {
  
          return Mono.subscriberContext().flatMap(ctx -&gt; {
  
              Mono blockingWrapper =  Mono.fromCallable(() -&gt;
                      service.getId(request)
                              .subscriberContext(ctx)
                              .subscribe(id -&gt; request.setId(id))
              ).subscribeOn(Schedulers.elastic());
  
              return blockingWrapper.flatMap(o -&gt; authService.getAccessToken()
                      .flatMap(token -&gt; post("/save", request,
                              token.getAccessToken(),
                              ctx)
                              .bodyToMono(ApplicationResponse.class))
                      .log());
          });
      }
  </code></pre>