title: Springboot : How to use WebClient instead of RestTemplate for Performing Non blocking and Asynchronous calls
body: <p>I have a springboot project which uses Springboot Resttemplate. We have moved to springboot 2.0.1 from 1.5.3 and we are trying to make
  the rest calls from it  asynchronous by using WebClient. We used to process the string received using Resttemplate as given below. But WebClient returns only
  data in Mono or Flux. How can I get the data as String. Already tried block() method , but it does asynchronous calls. </p>
  
  <pre class="lang-java prettyprint-override"><code>@Retryable(maxAttempts = 4, value = java.net.ConnectException.class,
             backoff = @Backoff(delay = 3000, multiplier = 2))
  public Mono&lt;String&gt; getResponse(String url) {
      return webClient.get().uri(urlForCurrent).accept(APPLICATION_JSON)
                      .retrieve()
                      .bodyToMono(String.class);
  }
  </code></pre>
  
  <p>Present Data flow with RestTemplate</p>
  
  <ol>
  <li>Controller receives the client call</li>
  <li>provider gets the data in String format </li>
  <li>Provider processes the String </li>
  <li>Data is given to controller</li>
  </ol>
  
  <p>Controller.java</p>
  
  <pre class="lang-java prettyprint-override"><code>@RequestMapping(value = traffic/, method = RequestMethod.GET,
                  produces = MediaType.APPLICATION_JSON_VALUE)
  public String getTraffic(@RequestParam("place") String location) throws InterruptedException, ExecutionException {
      String trafficJSON = Provider.getTrafficJSON(location)
      return trafficJSON;
  }
  </code></pre>
  
  <p>Provider.java</p>
  
  <pre><code>public String getTrafficJSON(String location) {
      String url = ----;
  
      ResponseEntity&lt;String&gt; response = dataFetcher.getResponse(url);
  
      /// RESPONSEBODY IS READ AS STRING AND IT NEEDS TO BE PROCESSED
      if (null != response {
          return parser.transformJSON(response.getBody(), params);
      }
  
      return null;
  }
  </code></pre>
  
  <p>DataFetcher.java</p>
  
  <pre class="lang-java prettyprint-override"><code>@Retryable(maxAttempts = 4,
             value = java.net.ConnectException.class,
             backoff = @Backoff(delay = 3000, multiplier = 2))
  public ResponseEntity&lt;String&gt; getResponse(String url) {
      /* ----------------------- */
      return getRestTemplate().getForEntity(urlForCurrent, String.class);
  }
  </code></pre>