0
0
Android Kotlinmobile~5 mins

Retrofit setup in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AAdd Retrofit dependency to build.gradle
BCreate an API interface
CCall the API directly
DWrite XML layout
Which Retrofit component sets the base URL for API calls?
ARetrofit.Builder().baseUrl()
BConverterFactory
CAPI interface
DCall object
What does GsonConverterFactory do in Retrofit?
AManages API keys
BHandles network errors
CConverts JSON to Kotlin objects
DCreates UI layouts
How do you declare a GET request in a Retrofit API interface?
AIn AndroidManifest.xml
BUsing a JSON file
CInside build.gradle
D@GET annotation on a function
Which return type is commonly used for Retrofit API calls with Kotlin coroutines?
AVoid
Bsuspend function returning data
CString
DInt
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.