Skip to main content

@Remote

The @Remote annotation is used on your interface class to identify it as a REST proxy interface.

Remotepath headers version versionHeader

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

@Remote(path)

The @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);

VarResolver.DEFAULT 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/headerList)

The @Remote(headers) and @Remote(headerList) annotations are used to add headers on all requests.

Example
@Remote(
path="/petstore",
headers={
"Foo: bar",
"Baz: $S{bazProperty}"
},
headerList=MyHeaderList.class
)
public interface PetStore {...}
// Our dynamic supplier.
public class MyHeaderList extends HeaderList {
...
}

@Remote(version/versionHeader)

The @Remote(version) and @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 "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 Client-Version is at least 2.0.
// Note that this also matches 2.0.1.
@RestGet(clientVersion="2.0")
public Object foo() {...}

// Call this method if Client-Version is at least 1.1 but less than 2.0.
@RestGet(clientVersion="[1.1,2.0)")
public Object foo() {...}

// Call this method if Client-Version is less than 1.1.
@RestGet(clientVersion="[0,1.1)")
public Object foo() {...}