Search code examples
dropwizardapi-design

Calling external API from dropwizard


I'm pretty new to Dropwizard and learning it (and API development in general).

I'm looking at Dropwizard to build an API which should call another API at somepoint.

More precisely, I have a json/yaml file which I'll convert it another json file consumable by an external API.

The API I'm building includes the whole processenter image description here

For now I'm focusing on the last part: calling external API (with a fixed json).so how can I hit an external API from within Dropwizard?

Here's the sudo code:

@Path("/my_api")
public class HelloResource {

@GET
@Produces(MediaType.APPLICATION_JSON)
public hit_external() {
    // call "my.external.api/ext_api"

}
}

Any comments/suggestions/link to references is really appreciated.


Solution

  • Thanks to Andre, I endded up using Dropwizard client (Jersey client):

    import javax.ws.rs.client.ClientBuilder;
    
    
        Client client = ClientBuilder.newClient();
        String result = client.target("http://path_to_external_resource").request().get(String.class);
    
        return result;