title: Spring WebFlux, extracting the request body
body: <p>I am writing a small WebFlux client proxy that will accept a POST request, extract the JSON content, and pass that on to a further call to a third party web server via another POST.  I want to get a hold of the json body in my original POST request.</p>
  <pre><code>curl --header &quot;Content-Type: application/json&quot; \
    --request POST \
    --data '{&quot;username&quot;:&quot;xyz&quot;, &quot;preference&quot;:&quot;123&quot;}' \
    http://localhost:3000/mih/search
  </code></pre>
  <p>Here is my route to handle the above POST:</p>
  <pre><code>@Bean
  open fun route(searchService: SearchService): RouterFunction&lt;ServerResponse&gt; {
      return RouterFunctions.route(
              RequestPredicates.POST(&quot;/search&quot;).and(RequestPredicates.accept(MediaType.APPLICATION_JSON)),
              HandlerFunction {
                      request: ServerRequest -&gt; searchService.search(request.body(BodyExtractors.toMono(String::class.java)))
              } )
      }
  </code></pre>
  <pre><code>open class SearchService(private val myWebClient: MyWebClient): ISearchService {
  
      override fun search(json: String): Mono&lt;ServerResponse&gt; {
          return myWebClient.myPost(json)
      }
  }
  </code></pre>
  <pre><code>import org.springframework.web.reactive.function.client.WebClient
  
  open class MyWebClient(
      private val springWebClient: WebClient,
      private val properties: properties ) : IMyWebClient {
  
      override fun myPost(json: String): Mono&lt;ServerResponse&gt; {
          return springWebClient.post()
              .uri(&quot;/{base}/queries&quot;, properties.getBase)
              .body(
                  BodyInserters.fromPublisher(Mono.just(json), String::class.java)
              ).retrieve().bodyToMono(
                  ServerResponse::class.java
              )
      }
  }
  </code></pre>
  <p>When I go to <code>.subscribe()</code> to the <code>Mono&lt;String&gt;</code> I get</p>
  <pre><code>Type mismatch.
    Required: String
    Found: Disposable
  </code></pre>
  <p>How do I successfully extract the body of the request?</p>