-
Notifications
You must be signed in to change notification settings - Fork 10
Resource Delegates
Christopher Viel edited this page Jan 6, 2015
·
17 revisions
This extension aims at making your resource interfaces (and annotations!) reusable by server implementations (DRY principle). To achieve this, the extension will generate a delegate that will wrap the call to the resource and to RestDispatch
.
-
Follow the setup instruction for Rest-Dispatch here.
-
Add the jar to your classpath. If you are using maven:
<dependency> <groupId>com.gwtplatform.extensions</groupId> <artifactId>dispatch-rest-delegates</artifactId> <version>${gwtp.version}</version> <scope>provided</scope> </dependency>
-
Inherit the extension in your GWT module file:
<inherits name="com.gwtplatform.dispatch.rest.delegates.ResourceDelegate"/>
The way you write resources and sub-resources doesn't change. However, the return type of your end-point is no longer limited to RestAction<?>
or a sub-resource. Your end-points can return any concrete class or primitives. The returned type must be the type of the expected result. ie:
@Path("/cars")
interface CarsResource {
// You can use sub-resources:
@Path("/{car-id}")
CarResource car(@PathParam("car-id") long id);
// You can return primitive or boxed types:
@GET
@Path("/count")
int count();
// You can return collections of concrete classes:
@GET
List<Car> allCars();
// You can mix with methods that return RestAction<?>
RestAction<Void> create(Car car);
}
interface CarResource {
// You can return any concrete class, as long as they are serializable:
@GET
Car get();
// Even void works:
@DELETE
void delete();
}
TODO
TODO