I am new to RESTful webservices. I am trying to get a JSON file from a RESTful web service of RIPE Atlas. The URL of the API is https://stat.ripe.net/data/abuse-contact-finder/data.json?resource=193/23. Please find my code below for retrieving the JSON file:
WebResource service = client.resource(UriBuilder.fromUri("https://stat.ripe.net/data/abuse-contact-finder/data.json").build());
// getting JSON data
System.out.println(service.path("resource=193/23").accept(MediaType.APPLICATION_JSON).get(String.class));
In this above case, I am getting 400 Bad request from the server. When i gave the complete URL, along with the request parameter "?resource=193/23" in 'fromUri', it is working fine. But when I specified the request parameter in the 'service.path' like above, it is not. What am I doing wrong? I am sure this is a silly question, forgive my ignorance, but could someone please guide me in the right direction?
I think you want to add the query param differently.
service.queryParam("resource","193/23").accept(MediaType.APPLICATION_JSON).get(String.class));
or
MultivaluedMap queryParams = new MultivaluedMapImpl();
queryParams.add("resource","193/23";
ClientResponse response = service.queryParams(queryParams).get(String.class));
I suggest you consider familiarizing yourself with the Jax-RS API here, it has a nice description of path as well.