1/15
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is Retrofit?
a type-safe HTTP client for Android and Java that simplifies interacting with REST APIs by handling request/response serialization and supporting common HTTP operations.
What is the Retrofit class used for?
acilitates network operations and is the main entry point for making HTTP requests.
What is a Converter Factory in Retrofit?
converts JSON or other data formats into POJOs (Plain Old Java Objects) and vice versa. GsonConverterFactory is commonly used for JSON conversion.
What is a Call object in Retrofit?
represents an HTTP request and is used to execute network requests and receive responses.
What is a Callback in Retrofit?
handles network responses asynchronously.
What does the Response object in Retrofit contain?
contains the actual HTTP response, including success or error details.
: What is a Request object in Retrofit?
represents the HTTP request sent to the server.
How do you add Retrofit dependencies in an Android project?
Add dependencies for Retrofit, Gson (for JSON serialization), and Coroutine support in the build.gradle
file.
How do you define a data model for Retrofit in Kotlin?
data class Post(
val id: Int,
val title: String,
val body: String
)
How do you define API endpoints in Retrofit?
interface ApiService {
@GET("posts")
suspend fun getPosts(): List<Post>
}
Why use a ViewModel for network calls in Jetpack Compose?
It keeps the UI layer clean, lifecycle-safe, and allows network requests to persist across configuration changes.
What is MockWebServer used for?
It simulates network requests and responses, allowing unit testing of Retrofit API calls.
Why is error handling important in Retrofit?
ensures a smooth user experience by managing network failures, parsing errors, and other issues.
What state management options are available for Retrofit data?
StateFlow and LiveData are commonly used to observe data changes and trigger UI updates.
Why should network requests be handled in the ViewModel?
Performing network requests in the ViewModel ensures data survives configuration changes and keeps the UI layer clean.
How does Kotlin coroutines help with Retrofit?
allow you to perform network requests asynchronously using suspend
functions, preventing UI thread blocking.