O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Service interface

Service (endpoint) interfaces are the core things when working with Retrofit library. Basically, they let you define the structure and parameters of HTTP requests by putting metadata on a simple Java Class interface.

Let's take a look at this example that we will use to query financial stocks:

import io.reactivex.Single;import retrofit2.http.GET;import retrofit2.http.Query;public interface YahooService {@GET("yql?format=json")    Single<YahooStockResult> yqlQuery(            @Query("q") String query,            @Query("env") String env    );}

Just by taking a quick look at this HTTP interface definition, we can already tell a few things:

  • There will be just a single object as a response of the YahooStockResult type
  • The first query parameter is

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required