Computer scienceMobileAndroidNetworking

Networking Basics

Theory

API Service

Report a typo

Read the code below. What should be written in the val apiService line to create an implementation of the ApiService interface?

interface ApiService {
  @GET("posts/{id}")
  suspend fun getPostById(@Path("id") id: Int): Post
}

val retrofit = Retrofit.Builder()
  .baseUrl("https://jsonplaceholder.typicode.com/")
  .addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
  .build()

val apiService = //here!

val post = apiService.getPostById(1)
Enter a short text
___

Create a free account to access the full topic