Skip to content

Instantly share code, notes, and snippets.

@maggandalf
Last active August 29, 2015 14:03
Show Gist options
  • Save maggandalf/ef8791fcfa7a35f4049c to your computer and use it in GitHub Desktop.
Save maggandalf/ef8791fcfa7a35f4049c to your computer and use it in GitHub Desktop.
@GET
@Path("{isbn}")
@Produces(MediaType.APPLICATION_JSON)
public void bookAndComment(@Suspended final AsyncResponse asyncResponse, @PathParam("isbn") String isbn) {
//Calling previous defined functions
Observable<JsonObject> bookInfo = getBookInfo(isbn);
Observable<JsonArray> comments = getComments(isbn);
Observable.zip(bookInfo, comments, (JsonObject book, JsonArray bookcomments) ->
Json.createObjectBuilder().add("book", book).add("comments", bookcomments).build()
)
.subscribe(new Subscriber<JsonObject>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
asyncResponse.resume(e);
}
@Override
public void onNext(JsonObject jsonObject) {
asyncResponse.resume(jsonObject);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment