VOOZH about

URL: https://www.geeksforgeeks.org/kotlin/how-to-update-data-in-api-using-retrofit-in-android-using-jetpack-compose/

⇱ How to Update Data in API using Retrofit in Android using Jetpack Compose? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Update Data in API using Retrofit in Android using Jetpack Compose?

Last Updated : 23 Jul, 2025

Android applications use APIs within Android Applications to access data from databases. We can perform several operations using APIs such as Reading, Writing, and Updating our Data in the Database. In this article, we will take a look at How to Update Data in API using Retrofit in Android using Jetpack Compose. 

Note: If you are seeking Java code for Jetpack Compose, please note that Jetpack Compose is only available in Kotlin. It uses features such as coroutines, and the handling of @Composable annotations is handled by a Kotlin compiler. There is no method for Java to access these. Therefore, you cannot use Jetpack Compose if your project does not support Kotlin.

Step by Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. While choosing the template, select Empty Compose Activity. If you do not find this template, try upgrading the Android Studio to the latest version. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project.

Step 2: Add the below Dependency to your build.gradle File

Below is the dependency for Volley which we will be using to get the data from API. For adding this dependency navigate to the app > Gradle Scripts > build.gradle(app) and add the below dependency in the dependencies section.

// below dependency for using retrofit.
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'

After adding this dependency sync your project and now move towards the AndroidManifest.xml part.

Step 3: Adding Internet Permissions in the AndroidManifest.xml File

Navigate to the app > AndroidManifest.xml and add the below code to it. 

Step 4: Creating a Model Class

Navigate to app > java > your app’s package name > Right-click on it > New > Java/Kotlin class and name your class as DataModel and add the below code to it. Comments are added in the code for further explanation.

Step 5: Creating an Interface Class for API Call

Navigate to the app > java > your app’s package name > Right-click on it > New > Kotlin class select it as RetrofitAPI and add below code to it. Comments are added in the code for further explanation.

Step 6: Working with MainActivity.kt file

Navigate to the app > java > your app’s package name > MainActivity.kt file and add the below code to it. Comments are added in the code for further explanation.

Now run your application to see the output of it. 

Output:

Comment

Explore