title: Shall I Make my REST Gateway a Library?
body: <p>Suppose there is a REST service with several clients. Each client has to do roughly the same to call the REST service: construct a URL, send a request, deserialize the response, map HTTP return codes to exceptions, etc.</p>
  
  <p>This seems to be duplicate code so maybe it's a good idea to put the REST gateway code into a reusable library. In Java this could look like the following:</p>
  
  <ul>
  <li>There is a jar file which depends on Jersey and contains the rest client code.</li>
  <li>The rest client is a simple class or CDI bean.</li>
  <li>All clients simply depend on this jar and call the members of the aforementioned class.</li>
  </ul>
  
  <p>So no client has to worry about REST and can just call methods.</p>
  
  <p>Is this a good idea?</p>
  
  <p>(this question originates from <a href="https://stackoverflow.com/questions/39913615/handling-exception-in-java-restclient/">this other question</a>)</p>