Created
May 12, 2016 13:53
-
-
Save leonmaia/e9f4b83eae7bd19dd1eaa95bc402cadf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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