java rest api案例,使用Java的REST API

I have a management web application located on a remote server. This app was written using a MEAN stack and I have a list of all the RESTful routes necessary to connect to the web app.

I am writing a Java client application that needs to send and receive data from this management app. How do connect the client to the web application if I have the server's IP address and REST routes?

I imagine that I need to provide a URL connection to the server and the REST API file and then just call the route functions like PUT and GET.

解决方案

There are plenty of libraries to consume REST applications in Java nowadays.

The standard

The JAX-RS Client API (javax.ws.rs.client package), defined in the JSR 339, is the standard way to consume REST web services in Java. Besides others, this specification is implemented by Jersey and RESTEasy.

JAX-RS vendor specific proxy-based clients

Both Jersey and RESTEasy APIs provide a proxy framework.

The basic idea is you can attach the standard JAX-RS annotations to an interface, and then implement that interface by a resource class on the server side while reusing the same interface on the client side by dynamically generating an implementation of that using java.lang.reflect.Proxy calling the right low-level client API methods.

For more details, check the following:

Other resources

There are a few other good options you may consider as alternative to the JAX-RS Client API:

你可能感兴趣的:(java,rest,api案例)