The REST client API allows you to access REST interfaces using POJOs:
The client API uses the same serializers and parsers (and subsequently their flexibility and configurability) as the server side to marshall POJOs back and forth.
The remote proxy interface API allows you to invoke server-side POJO methods on the client side using REST (i.e. RPC over REST):
Although the client API is not dependent on the
juneau-rest-server module, the server
module provides some convenience APIs for exposing remoteable proxies on the server side:
annotation on a Java method.
RemoteableServlet class is a simple specialized servlet with an abstract
method to define the server-side POJOs:
approach is easier if you only have a single interface you want to expose.
You simply define a Java method whose return type is an interface, and return the implementation of that interface:
In either case, the proxy communications layer is pure REST. Parameters passed in on the client side are serialized as an HTTP POST, parsed on the server side, and then passed to the invocation method. The returned POJO is then marshalled back as an HTTP response.
In most cases, you'll want to use JSON or MessagePack as your communications layer since these are the most efficient. Although remoteable proxies work perfectly well for any of the other supported languages. For example, RPC over Turtle!
The parameters and return types of the Java methods can be any of the supported serializable and parsable types in POJO Categories. This ends up being WAY more flexible than other proxy interfaces since Juneau can handle so may POJO types out-of-the-box. Most of the time you don't even need to modify your existing Java implementation code.
RemoteableServlet class itself shows how sophisticated REST interfaces can be built on the Juneau REST Servlet
API using very little code.
The class consists of only 53 lines of code, yet is a sophisticated discoverable and self-documenting REST interface.
And since the remote proxy API is built on top of REST, it can be debugged using just a browser.
Remoteable proxies can also be used to define interface proxies against 3rd-party REST interfaces. This is an extremely powerful feature that allows you to quickly define easy-to-use interfaces against virtually any REST interface.
Similar in concept to remoteable services defined above, but in this case we simply define our interface with special annotations that tell us how to convert input and output to HTTP headers, query parameters, form post parameters, or request/response bodies.