I am trying to create a web API using Jersey. I am trying to run a method similar to this:
WebResource r = c.resource("http://localhost:8080/Jersey/rest/contacts");
However Jersey 2.x does not have a WebResource
or Resource
class. So what class can I use instead in order to have the uri http://localhost:8080/Jersey/rest/contacts
as a parameter?
This will be ran in a ContactClient
class
Have a look at the Client API from the Jersey documentation. With Jersey 2.x you instead want to use WebTarget
. For example
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url);
Response response = target.request().get();
See the documentation I linked to for much more information and examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With