1

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.

2 Answers 2

5

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;
3

You can use the Dropwizard Client module, which relies on the Apache HttpClient (default) or the Jersey Client. Once the client is configured in the DW application just use that to make the external calls. For an higher-level abstraction Feign is a good option.

Be aware that when making synchronous calls to an external web service the application might run out of available threads if those are waiting on the other service. You should make this calls asynchronous if possible for example using a queue of external calls to be processed and having the clients of the API to check the status of that request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.