title: Java REST API POST return Future
body: <p>In one of my projects I want to develop Asynchronous REST API in Spring Boot (1.5.8) with POST because the code executed by the API is very long. </p>
  
  <p>First question is: Does it make sense to return a <code>CallableFuture</code> from a POST request?
  If so how to block the client until the effective response comes? </p>
  
  <p>Here it is the code of my REST API: </p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  public CompletableFuture&lt;String&gt; postAPI(@RequestBody() String param) { 
  LOGGER.info("I received a POST request");
  CompletableFuture&lt;String&gt; result = CompletableFuture.completedFuture(function(param));
  return result;}
  </code></pre>
  
  <p>And following is the code I'm using to call it and retrieve the result. </p>
  
  <pre><code>ListenableFuture&lt;ResponseEntity&lt;String&gt;&gt; response = restTemplate
      .exchange(uri, HttpMethod.POST, entity,
          String.class);
  ResponseEntity&lt;String&gt; result = response.get();
  String response = result.getBody();
  </code></pre>
  
  <p>The <code>response.get()</code> doesn't actually block the execution, so the <code>getBody()</code> always returns null. </p>