@RemoteOp
The @RemoteOp annotation is applied to methods of @Remote-annotated interfaces to identify REST endpoints.
Specialized sub-annotations are provided for common HTTP methods:
@RemoteOp(method/path)
The HTTP method and path are mapped to a Java method using the method
and path
annotations.
@Remote
public interface PetStore {
// GET /pets/{petId}
@RemoteGet("/pets/{petId}")
Pet getPet(@Path("petId") int id);
}
The Java method name can be anything.
Inferred method/path
In such cases, method
and path
annotations are optional if you follow certain naming conventions on your method that
identify the method and path.
For example, the getPet
method below defaults to GET /pet
:
@Remote
public interface PetStore {
// GET /pet
@RemoteOp
Pet getPet(...);
}
In such cases, the @RemoteOp annotation is optional. Method names matching the following pattern are assumed to be implying the HTTP method name:
(get|put|post|delete|options|head|connect|trace|patch).*
do(?i)(get|put|post|delete|options|head|connect|trace|patch)
Java method name | Inferred HTTP method | Inferred HTTP path |
---|---|---|
getPet() | GET | /pet |
get() | GET | / |
postPet() | POST | /pet |
fooPet() | [default] | /fooPet |
doGet() | GET | / |
doGET() | GET | / |
doFoo() | [default] | /doFoo |
@RemoteOp(returns)
The return type of the Java methods can be any of the following:
-
void/Void
- Don't parse any response.
- Note that the method will still throw a runtime exception if an error HTTP status is returned.
-
Any parseable POJO
- The body of the response will be converted to the POJO using the parser defined on the
RestClient
based on theContent-Type
of the response.
- The body of the response will be converted to the POJO using the parser defined on the
-
Any @Response-annotated type
- For returning custom response objects with status codes and headers.
-
HttpResponse
- Returns the raw
HttpResponse
returned by the innerHttpClient
.
- Returns the raw
-
- Returns access to the raw reader of the response.
-
- Returns access to the raw input stream of the response.
-
- Of any type on this list for asynchronous processing.
If you're only interested in the HTTP status code of the response, you can use the returns annotation with a value of STATUS:
@Remote
public interface PetStore {
// POST /pets
// Returns HTTP status code.
@RemotePost(returns=STATUS)
int pets(...);
}
If your RestClient
does not have a parser associated with it, then the value is converted directly from a String using
the rules defined in POJO Categories.