Complete the code to define a Retrofit API interface method for a GET request.
interface ApiService {
@GET("users")
fun getUsers(): [1]<List<User>>
}The Retrofit interface method returns a Call object for asynchronous requests.
Complete the code to define a POST request method with a JSON body parameter.
interface ApiService {
@POST("posts")
suspend fun createPost(@Body [1]: Post): Response<Post>
}The parameter name can be anything, but post is a clear and common choice.
Fix the error in the interface method to correctly define a query parameter.
interface ApiService {
@GET("search")
suspend fun searchUsers(@Query("query") [1]: String): Response<List<User>>
}The parameter name must match the query key or be clearly related; here, 'query' matches the @Query key.
Fill both blanks to define a header parameter and a path parameter in the API interface.
interface ApiService {
@GET("users/[1]")
suspend fun getUser(@Header("Authorization") [2]: String): Response<User>
}The path parameter is typically named userId to identify the user, and the header parameter for authorization is commonly named authToken.
Fill all three blanks to define a PATCH request with path, header, and body parameters.
interface ApiService {
@PATCH("posts/[1]")
suspend fun updatePost(@Header("Authorization") [2]: String, @Body [3]: Post): Response<Post>
}The path parameter is postId to identify the post, the header parameter is token for authorization, and the body parameter is post representing the updated post data.