@Get("/group/:groupId")
public void delete(final HttpServerRequest request) {
String groupId = request.params().get("groupId");
}
REST
ODE Framework offers, on top of Vertx2, an "annotation API" to implement a REST API. It makes it possible to map a controller method with a path (a route) by annotation. There are two ideas behind that approach :
-
provide a descriptive style at code time (that reminds JAX-RS for Java developers)
-
keep asynchronous vertx2 execution at runtime
Note
|
With ODE annotations you don’t need to manage a vertx2 RouteMatcher. The URL path format follows the verxt2 one (for parameter extraction, pattern matching …) . See Vert2 manual |
HTTP method
Note
|
Annotations are shipped in the import fr.wseduc.rs package.
|
GET
DELETE
@Delete("/group/:groupId")
public void delete(final HttpServerRequest request) {
String groupId = request.params().get("groupId");
}
PUT
@Put("/group/:groupId")
public void update(final HttpServerRequest request) {
bodyToJson(request, new Handler<JsonObject>() {
@Override
public void handle(JsonObject body) {
// modification's stuff with the body object
}
});
}
Note
|
bodyToJson is a static method provided by fr.wseduc.webutils.request.RequestUtils .
It wraps vertx2 request.bodyHandler in order to strip common XSS pattern from the request body.
|
POST
@Post("/group/:groupId")
public void create(final HttpServerRequest request) {
bodyToJson(request, new Handler<JsonObject>() {
@Override
public void handle(JsonObject body) {
// creation's stuff with the body object
}
});
}