Creating an API interface

To get a REST API response, we need to create an interface where we will mention what we want to do with the data, such as getting the user list, creating a new user, and deleting or updating the user details. Let's create an interface named UserInterface.kt.

Here is the code of the interface:

interface UserInterface {
fun getAllUserList(): List<UserModel>
fun getUserByID(id: Int): UserModel?
fun addNewUser(userModel: UserModel)
fun updateUser(userModel: UserModel)
fun deleteUser(id: Int)
}

We have used five functions, which are explained as follows:

  • getAllUserList(): This will return a list of the details of all users
  • getUserByID(id: Int): This will return the details of a specific user
  • addNewUser(userModel: UserModel): This will add new user details
  • updateUser(userModel: UserModel): This will update an existing user's details
  • deleteUser(id: Int): This will delete a specific user
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.88.54