Book Image

Learning Reactive Programming with Java 8

By : Nickolay Tzvetinov
Book Image

Learning Reactive Programming with Java 8

By: Nickolay Tzvetinov

Overview of this book

Table of Contents (15 chapters)
Learning Reactive Programming with Java 8
About the Author
About the Reviewers

An HTTP client example

Let's use RxJava to retrieve information about the GitHub repositories of a user by username. We will use our subscribePrint() function used previously to output the information to the system output. The idea of the program is to display all of the public repositories of the user that are not forks. The main part of the program looks like this:

String username = "meddle0x53";
Observable<Map> resp = githubUserInfoRequest(client, username);
  .map(json ->
    json.get("name") + "(" + json.get("language") + ")"),

This program uses my user (it can be easily reworked to use a username passed as a parameter) to retrieve information its public repositories. It prints the name of each repository and the main programming language used in it. The repositories are represented by Map instances generated from the incoming JSON file, so we can read repository properties from them.

These JSON Map instances are emitted by an Observable instance...