Recall & Review
beginner
What is an API interface in Android Kotlin development?
An API interface in Android Kotlin defines how your app communicates with a web service. It declares functions that represent HTTP requests, like GET or POST, to fetch or send data.
Click to reveal answer
beginner
What Kotlin library is commonly used to define API interfaces for network calls?
Retrofit is a popular Kotlin library that helps define API interfaces. It uses annotations to describe HTTP methods and endpoints, making network calls easy and type-safe.
Click to reveal answer
intermediate
Explain the role of annotations like @GET and @POST in API interface definition.
Annotations like @GET and @POST tell Retrofit what kind of HTTP request to make and which endpoint to call. For example, @GET("users") means a GET request to the "users" path.
Click to reveal answer
intermediate
How do you define a function in an API interface to send a POST request with a JSON body?
You define a function with @POST annotation and use @Body parameter to pass the JSON data. For example: @POST("login") suspend fun login(@Body user: User): Response<Token>
Click to reveal answer
intermediate
Why use suspend functions in API interface definitions with Retrofit and Kotlin?
Suspend functions allow network calls to run asynchronously without blocking the main thread. This keeps the app responsive while waiting for the server response.
Click to reveal answer
Which annotation is used to define a GET request in a Retrofit API interface?
✗ Incorrect
The @GET annotation specifies that the function will perform an HTTP GET request.
In Retrofit, how do you pass data in the body of a POST request?
✗ Incorrect
The @Body annotation is used to send data as the request body in POST requests.
What keyword is used in Kotlin to make a network call asynchronous in an API interface?
✗ Incorrect
The suspend keyword marks a function as asynchronous, allowing it to be called within coroutines.
Which library is commonly used to create API interfaces in Android Kotlin?
✗ Incorrect
Retrofit is the standard library for defining API interfaces and making network calls.
What does the @Path annotation do in a Retrofit API interface?
✗ Incorrect
@Path replaces a placeholder in the URL path with a method parameter value.
Describe how to define a simple Retrofit API interface in Kotlin for a GET request to fetch a list of users.
Think about the function signature and the annotation needed.
You got /4 concepts.
Explain why suspend functions are important in API interface definitions when using Retrofit with Kotlin coroutines.
Consider what happens during network calls and UI updates.
You got /4 concepts.