0
0
Android Kotlinmobile~10 mins

API interface definition 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 define a Retrofit API interface method for a GET request.

Android Kotlin
interface ApiService {
    @GET("users")
    fun getUsers(): [1]<List<User>>
}
Drag options to blanks, or click blank then click option'
ACall
BResponse
CDeferred
DObservable
Attempts:
3 left
💡 Hint
Common Mistakes
Using Response instead of Call causes compilation errors.
Using Deferred requires additional coroutine setup.
2fill in blank
medium

Complete the code to define a POST request method with a JSON body parameter.

Android Kotlin
interface ApiService {
    @POST("posts")
    suspend fun createPost(@Body [1]: Post): Response<Post>
}
Drag options to blanks, or click blank then click option'
ApostData
BpostBody
Cbody
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using ambiguous parameter names reduces code clarity.
Forgetting the @Body annotation causes runtime errors.
3fill in blank
hard

Fix the error in the interface method to correctly define a query parameter.

Android Kotlin
interface ApiService {
    @GET("search")
    suspend fun searchUsers(@Query("query") [1]: String): Response<List<User>>
}
Drag options to blanks, or click blank then click option'
AsearchTerm
BqueryString
Cquery
Dterm
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name different from the query key without specifying it causes errors.
Omitting the @Query annotation breaks the query parameter.
4fill in blank
hard

Fill both blanks to define a header parameter and a path parameter in the API interface.

Android Kotlin
interface ApiService {
    @GET("users/[1]")
    suspend fun getUser(@Header("Authorization") [2]: String): Response<User>
}
Drag options to blanks, or click blank then click option'
AuserId
BauthToken
Ctoken
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using ambiguous names for path or header parameters.
Forgetting to annotate parameters with @Header or path placeholder.
5fill in blank
hard

Fill all three blanks to define a PATCH request with path, header, and body parameters.

Android Kotlin
interface ApiService {
    @PATCH("posts/[1]")
    suspend fun updatePost(@Header("Authorization") [2]: String, @Body [3]: Post): Response<Post>
}
Drag options to blanks, or click blank then click option'
ApostId
BauthHeader
Cpost
Dtoken
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up parameter names causing confusion.
Omitting necessary annotations like @Body or @Header.