Unit3 - Subjective Questions

CSE227 • Practice Questions with Detailed Answers

1

Define Retrofit and explain its primary advantages over traditional Android networking libraries like HttpURLConnection or Volley for advanced Android app development. Why is it a preferred choice for building REST clients?

2

Describe the core components involved in setting up and making a basic API request using Retrofit. Explain the role of each component.

3

Outline the step-by-step process to integrate Retrofit into an existing Android project, from adding dependencies to making your first API call.

4

Explain the role and significance of a ConverterFactory in Retrofit. Provide an example of how to configure Retrofit to use a GsonConverterFactory and briefly describe how it handles data serialization and deserialization.

5

Explain how to make different types of HTTP requests (GET, POST, PUT, DELETE) using Retrofit annotations. Provide a simple example for each request type within a single API service interface.

6

Explain how to pass query parameters and path parameters in a Retrofit request. Provide a concrete example for both in a single API service interface method.

7

Describe how to send a request body (e.g., a JSON object) with a POST request using Retrofit. Provide a complete example including the data model, API service interface, and the code to initiate the request.

8

What is the purpose of @Header and @Headers annotations in Retrofit? When would you use each, and what are their key differences?

9

Explain the role of data models (POJOs/data classes) in Retrofit for parsing JSON responses. How does a converter factory interact with these data models to facilitate data exchange?

10

Describe the process of receiving a JSON response from an API and converting it into Java objects using Retrofit. Include the key components involved in this conversion.

11

Describe the necessary steps to display parsed data from a Retrofit API response in an Android UI component like a RecyclerView. Include considerations for background processing and UI updates.

12

What strategies can be employed to handle complex JSON structures (e.g., nested objects, arrays of objects, varied types) when defining data models for Retrofit and its converter factories?

13

Explain the concept of asynchronous networking in Android development. Why is it crucial to perform network operations off the main thread, and what happens if they are not?

14

Compare and contrast using enqueue() with execute() in Retrofit for making API calls. When would you typically use each method in Android development?

15

Describe how to integrate Retrofit with Kotlin Coroutines for asynchronous API calls. Provide a simple example of a suspend function in an API service interface and its invocation from a ViewModel.

16

Explain common authentication mechanisms used with REST APIs (e.g., API Keys, Basic Authentication, Token-Based Authentication/OAuth 2.0). Briefly describe their principles.

17

How can you add an API key as a query parameter or a header to all Retrofit requests? Explain both approaches and discuss when one might be preferred over the other.

18

Describe how to implement token-based authentication (e.g., Bearer token) using an Interceptor in Retrofit's OkHttpClient. Provide a code example for the Interceptor and its integration.

19

What is an OkHttpClient Interceptor, and how is it used in conjunction with Retrofit for tasks like logging, authentication, or request modification?

20

In the context of asynchronous networking, explain the significance of the Dispatchers.IO and Dispatchers.Main in Kotlin Coroutines for handling Retrofit API calls and updating the UI.