title: Simple REST API calls using Spring?
body: <p>Okay I'm having a simple REST API that is now running. I also got a mobile app (Android) that would be ready for some network communication. But here is the thing:</p>
  
  <p>I now got a fancy API created with <a href="https://spring.io/" rel="nofollow">Spring</a> that I can use with Http-Requests:</p>
  
  <pre><code>package com.helloworld
  
  @Controller
  @RequestMapping("/helloWorld")
  public class HelloWorldController {
  
      @RequestMapping(value = "/hello", method = RequestMethod.GET)
      public String hello(ModelMap model) {
          model.addAttribute("msg", "JCG Hello World!");
          return "helloWorld";
      }
  }
  </code></pre>
  
  <p>This is all fine but how would I use this API in my Android mobile App? What I mean is that I don't know how to make those calls more elegantly and simple! I don't want to write for every request on my API something like this:</p>
  
  <pre><code>class HelloWorldTask extends AsyncTask&lt;String, String, String&gt; {
  
      private String url = "http://192.168.42.229:8080/HelloWorldExample/helloWorld/displayMessage/" + msg; 
  
      @Override
      protected String doInBackground(String... uri) {
  
          String msg = "";
          for(String m : uri) { msg += m; }    
  
          RestTemplate restTemplate = new RestTemplate();    
          restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
          return restTemplate.getForObject(url, String.class, "Android");
      }
  }
  </code></pre>
  
  <p>Is there any way to avoid this? To be honest I believed that I would be able to just import something like a <code>helloworld-api.jar</code> after building my REST API project and then do something like this:</p>
  
  <pre><code>import com.helloworld
  
  public void getServerHello() {
  
      HelloWorldController api;
  
      HelloWorld helloWorld = api.getHelloWorldMapping();
      helloWorld.displayMessage("How are you?");
  }
  </code></pre>
  
  <p>And that this will be it. So is there a way to do something like this when writing a Spring REST API or will I really have to use something like a URI-builder and create for all kind of requests an additional <code>class &lt;whatever&gt;Task extends AsyncTask&lt;?, ?, ?&gt;</code> by myself? </p>
  
  <p>Since the API is clearly defined it should be possible to do something like this, but is it?</p>
  
  <p>I hope my question is clear - please let me know if not.</p>