Skip to content

Instantly share code, notes, and snippets.

@leonmaia
Created May 12, 2016 13:53
Show Gist options
  • Save leonmaia/e9f4b83eae7bd19dd1eaa95bc402cadf to your computer and use it in GitHub Desktop.
Save leonmaia/e9f4b83eae7bd19dd1eaa95bc402cadf to your computer and use it in GitHub Desktop.
static Service<Request, Response> echoHandler() {
return new Service<Request, Response>() {
public Future<Response> apply(Request request) {
Cat cat = CatService.find(getId(request));
Response response = Response.apply(request.version(), Status.Ok());
response.setContent(ChannelBuffers.wrappedBuffer(toBytes(cat)));
return Future.value(response);
}
private int getId(Request request) {
String id = request.getParam("id");
try {
return parseInt(id);
} catch (NumberFormatException e) {
throw new NumberFormatException("Invalid id: " + id);
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment