title: Asynchronous REST client
body: <p>How to write <strong>asynchronous</strong> REST client?</p>
  
  <p>My <em>controller</em> (not sure if it's enough for being <em>async</em>):</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET, value = "/get/all")
  @ResponseBody
  public Callable &lt; CustomersListDTO &gt; getAllCustomers() {
      return new Callable &lt; CustomersListDTO &gt; () {
  
          @Override
          public CustomersListDTO call() throws Exception {
              Thread.sleep(2000);
              return customerService.getAllCustomers();
          }
  
      };
  }
  </code></pre>
  
  <p><br>
  My synchronous REST <em>client</em> method:</p>
  
  <pre><code>public Response get_all_customers() {
      ResponseEntity &lt; CustomersListDTO &gt; response;
      try {
          response = restTemplate.getForEntity(
              getMethodURI(ServiceExplanation.GET_ALL_CUSTOMERS),
              CustomersListDTO.class
          );
          message = "Customers obtained successfully!";
      } catch (HttpServerErrorException ex) {
          message = "ERROR: " + ex.getMessage() + " - " + ex.getResponseBodyAsString();
      } catch (HttpClientErrorException ex) {
          message = "ERROR: " + ex.getMessage() + " - " + ex.getResponseBodyAsString();
      } catch (RestClientException ex) {
          message = checkIfServerOrInternetDown();
      }
  
      return formResponse(message, response);
  }
  </code></pre>
  
  <p><br>
  How do I make it <em>asynchronous</em>? How can the CLIENT continue doing other tasks while SERVER is obtaining data and later return found data?</p>