Recall & Review
beginner
What is Retrofit in Android development?
Retrofit is a type-safe HTTP client for Android and Java. It helps you easily connect your app to web services by turning HTTP API into Kotlin interfaces.
Click to reveal answer
beginner
Which dependency do you add to your build.gradle to use Retrofit?
You add
implementation 'com.squareup.retrofit2:retrofit:2.9.0' to your app's build.gradle file to include Retrofit.Click to reveal answer
intermediate
How do you create a Retrofit instance in Kotlin?
Use
Retrofit.Builder() to set the base URL and converter, then call build(). For example:<br>val retrofit = Retrofit.Builder()
.baseUrl("https://api.example.com/")
.addConverterFactory(GsonConverterFactory.create())
.build()Click to reveal answer
intermediate
What is the role of a ConverterFactory in Retrofit?
ConverterFactory converts JSON or other data formats from the web service into Kotlin objects and vice versa. GsonConverterFactory is commonly used for JSON.
Click to reveal answer
intermediate
How do you define an API interface for Retrofit?
Create a Kotlin interface with functions annotated with HTTP methods like @GET or @POST. Each function returns a Call or suspend function for coroutines. Example:<br>
interface ApiService {
@GET("users")
suspend fun getUsers(): List<User>
}Click to reveal answer
What is the first step to use Retrofit in your Android app?
✗ Incorrect
You must first add the Retrofit library dependency to your project before using it.
Which Retrofit component sets the base URL for API calls?
✗ Incorrect
The baseUrl() method in Retrofit.Builder sets the root URL for all API requests.
What does GsonConverterFactory do in Retrofit?
✗ Incorrect
GsonConverterFactory converts JSON responses into Kotlin data classes and vice versa.
How do you declare a GET request in a Retrofit API interface?
✗ Incorrect
You use the @GET annotation on a function inside the API interface to declare a GET request.
Which return type is commonly used for Retrofit API calls with Kotlin coroutines?
✗ Incorrect
Using suspend functions allows Retrofit to work smoothly with Kotlin coroutines for asynchronous calls.
Explain the steps to set up Retrofit in an Android Kotlin project.
Think about what you need to add, build, and define before making API calls.
You got /4 concepts.
Describe how Retrofit converts JSON responses into Kotlin objects.
Focus on the part that changes raw data into usable app data.
You got /3 concepts.