title: DropWizard/Jersey API Clients
body: <p><a href="http://dropwizard.github.io/dropwizard/index.html">DropWizard</a> uses <a href="https://jersey.java.net/">Jersey</a> under the hood for REST. I am trying to figure out how to write a client for the RESTful endpoints my DropWizard app will expose.</p>
  
  <p>For the sake of this example, let's say my DropWizard app has a <code>CarResource</code>, which exposes a few simple RESTful endpoints for CRUDding cars:</p>
  
  <pre><code>@Path("/cars")
  public class CarResource extends Resource {
      // CRUDs car instances to some database (DAO).
      public CardDao carDao = new CarDao();
  
      @POST
      public Car createCar(String make, String model, String rgbColor) {
          Car car = new Car(make, model, rgbColor);
          carDao.saveCar(car);
  
          return car;
      }
  
      @GET
      @Path("/make/{make}")
      public List&lt;Car&gt; getCarsByMake(String make) {
          List&lt;Car&gt; cars = carDao.getCarsByMake(make);
          return cars;
      }
  }
  </code></pre>
  
  <p>So I would <em>imagine</em> that a structured API client would be something like a <code>CarServiceClient</code>:</p>
  
  <pre><code>// Packaged up in a JAR library. Can be used by any Java executable to hit the Car Service
  // endpoints.
  public class CarServiceClient {
      public HttpClient httpClient;
  
      public Car createCar(String make, String model, String rgbColor) {
          // Use 'httpClient' to make an HTTP POST to the /cars endpoint.
          // Needs to deserialize JSON returned from server into a `Car` instance.
          // But also needs to handle if the server threw a `WebApplicationException` or
          // returned a NULL.
      }
  
      public List&lt;Car&gt; getCarsByMake(String make) {
          // Use 'httpClient' to make an HTTP GET to the /cars/make/{make} endpoint.
          // Needs to deserialize JSON returned from server into a list of `Car` instances.
          // But also needs to handle if the server threw a `WebApplicationException` or
          // returned a NULL.
      }
  }
  </code></pre>
  
  <p>But the only two official references to Drop Wizard clients I can find are totally contradictory to one another:</p>
  
  <ul>
  <li><a href="http://dropwizard.github.io/dropwizard/manual/core.html#organizing-your-project">DropWizard recommended project structure</a> - which claims I should put my client code in a <code>car-client</code> project under <code>car.service.client</code> package; but then...</li>
  <li><a href="http://dropwizard.github.io/dropwizard/manual/client.html">DropWizard Client manual</a> - which makes it seem like a "DropWizard Client" is meant for integrating my DropWizard app with <em>other</em> RESTful web services (thus acting as a middleman).</li>
  </ul>
  
  <p>So I ask, what is the standard way of writing Java API clients for your DropWizard web services? Does DropWizard have a client-library I can utilize for this type of use case? Am I supposed to be implementing the client via some Jersey client API? Can someone add pseudo-code to my <code>CarServiceClient</code> so I can understand how this would work?</p>