{8.1.2-updated,8.2.0-updated} @Remote

The {@link oaj.http.remote.Remote @Remote} annotation is used on your interface class to identify it as a REST proxy interface.

The @Remote annotation is optional, but often included for code readability.

@Remote(path)

The {@link oaj.http.remote.Remote#path @Remote(path)} annotation is used to define the HTTP path of the REST service.

The path can be an absolute path to your REST service.

Example:

@Remote(path="http://localhost:10000/petstore") public interface PetStore {...}

PetStore store = client.getRemote(PetStore.class);

{@doc DefaultVarResolver} can also be used in the path.

Example:

// URL is specified via a system property. @Remote(path="$S{PetStoreUrl}") public interface PetStore {...}

When a relative path is specified, it's relative to the root-url defined on the RestClient used to instantiate the interface.

Example:

@Remote(path="/petstore") public interface PetStore {...}

RestClient client = RestClient .create() .json() .rootUrl("http://localhost:10000") .build(); PetStore store = client.getRemote(PetStore.class);

When no path is specified, the root-url defined on the RestClient is used.

Example:

@Remote public interface PetStore {...}

RestClient client = RestClient .create() .json() .rootUrl("http://localhost:10000/petstore") .build(); PetStore store = client.getRemote(PetStore.class);

@Remote(headers/headerSupplier)

The {@link oaj.http.remote.Remote#headers @Remote(headers)} and {@link oaj.http.remote.Remote#headerSupplier @Remote(headerSupplier)} annotations are used to add headers on all requests.

Example:

@Remote( path="/petstore", headers={ "Foo: bar", "Baz: $S{bazProperty}" }, headerSupplier=MyDynamicHeaderSupplier.class ) public interface PetStore {...}

// Our dynamic supplier. public class MyHeaderSupplier extends HeaderSupplier { // Headers can be added here at runtime. public static HeaderSupplier DYNAMIC_HEADERS = new HeaderSupplier(); public MyHeaderSupplier() { add("Qux","q2x"); add(DYNAMIC_HEADERS); } }

@Remote(version/versionHeader)

The {@link oaj.http.remote.Remote#version @Remote(version)} and {@link oaj.http.remote.Remote#versionHeader @Remote(versionHeader)} annotations are used to specify the client-side version of this interface that can be used on the server side to perform version-specific handling.

Example:

@Remote( path="/petstore", version="1.2.3" // Adds "X-Client-Version: 1.2.3" header to all requests. ) public interface PetStore {...}

This can be used in conjunction with the server-side client-versioning support.

// Call this method if X-Client-Version is at least 2.0. // Note that this also matches 2.0.1. @RestMethod(clientVersion="2.0") public Object getFoo() {...} // Call this method if X-Client-Version is at least 1.1, but less than 2.0. @RestMethod(clientVersion="[1.1,2.0)") public Object getFoo() {...} // Call this method if X-Client-Version is less than 1.1. @RestMethod(clientVersion="[0,1.1)") public Object getFoo() {...}