Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public interface RouteDSL {
RouteDSL param(String paramName, Handler<RoutingContext> checker)
default<T> RouteDSL param(String paramName, Function<String, T> checker) {
return param(paramName, ctx -> {
String p = ctx.request().getParam(name);
try {
ctx.put(paramName, checker.apply(p));
ctx.next();
} catch(Exception e) {
ctx.response().setStatusCode(400).end("Invalid parameter " + name);
}
};
}
RouteDSL param(String paramName, Handler<RoutingContext> checker)
default<T> RouteDSL asyncParam(String paramName, Function<String, Future<T>> checker) {
return param(paramName, ctx -> {
String p = ctx.request().getParam(name);
checker.apply(p).setHandler(res -> {
if (res.failed()) {
ctx.fail(res.cause());
} else {
ctx.put(paramName, res.result());
ctx.next();
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.