0
0
Android Kotlinmobile~10 mins

Retrofit setup in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Retrofit instance with the base URL.

Android Kotlin
val retrofit = Retrofit.Builder()
    .baseUrl("[1]")
    .build()
Drag options to blanks, or click blank then click option'
A"api.example.com"
B"https://api.example.com/"
C"http://api.example.com"
D"https://example.com/api"
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the scheme (http/https) causes errors.
Forgetting the trailing slash at the end of the URL.
2fill in blank
medium

Complete the code to add a JSON converter factory to Retrofit.

Android Kotlin
val retrofit = Retrofit.Builder()
    .baseUrl("https://api.example.com/")
    .addConverterFactory([1].create())
    .build()
Drag options to blanks, or click blank then click option'
AGsonConverterFactory
BJsonConverterFactory
CMoshiConverterFactory
DXmlConverterFactory
Attempts:
3 left
💡 Hint
Common Mistakes
Using a converter factory that does not match the data format.
Forgetting to add the converter factory causes parsing errors.
3fill in blank
hard

Fix the error in the Retrofit builder code by completing the blank.

Android Kotlin
val retrofit = Retrofit.Builder()
    .baseUrl("https://api.example.com/")
    .addConverterFactory(GsonConverterFactory.[1]())
    .build()
Drag options to blanks, or click blank then click option'
AgetInstance
Bnew
Cbuild
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'new' keyword which is invalid in Kotlin.
Using 'build' or 'getInstance' which do not exist for this class.
4fill in blank
hard

Fill both blanks to define a Retrofit service interface with a GET request.

Android Kotlin
interface ApiService {
    @[1]("users")
    fun getUsers(): [2]<List<User>>
}
Drag options to blanks, or click blank then click option'
AGET
BPOST
CCall
DResponse
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of GET for fetching data.
Using Response instead of Call as the return type.
5fill in blank
hard

Fill all three blanks to build a Retrofit instance with base URL, JSON converter, and create the service.

Android Kotlin
val retrofit = Retrofit.Builder()
    .baseUrl([1])
    .addConverterFactory([2].create())
    .build()

val service = retrofit.[3](ApiService::class.java)
Drag options to blanks, or click blank then click option'
A"https://api.example.com/"
BGsonConverterFactory
Ccreate
DcreateService
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'createService' instead of 'create' method on retrofit.
Missing quotes around the base URL.
Using wrong converter factory.