Retrofit JSON Http API
Sometimes we might need to send requests over HTTP, and receive JSON response from the server. In this case, we can use the injectable candy provided by the Reactant.
Reactant will call the Retrofit library which is one of the most popular Java HTTP client libraries, and create a service object based on the interface you provided.
JSON is the most common way to transfer data nowadays, so that currently we only support direct injection of JSON response API, discuss with us if you found other important use cases that JSON API cannot fulfill your requirements. Merge requests are welcome!
Now we use a funny API called PokeAPI as an example, which allows us to get the info of the pokemon with the API!
Inject the API
To use the API we declared, we can simply inject it with
RetrofitJsonAPI<T>, and call the function we just created.
Following examples shows how to make the request in the synchronous way and asynchronously way using the schedulers.
Different base url for different instance
To have different base url for each injection, you can specify the base url in
You can also turn on your API debugging feature by setting
debugging = true to your service instance,
which will enable the request logging.