Creating a user model

We'll fetch the REST API of our basic authentication-based Spring project, which was created using basic authentication. Although the REST API has four entities (id, name, email, and contactNumber), we'll create a model based on this REST API.

Here's the output of the REST API where we can see five users' details:

According to the API, we'll create a user model for the client side. Here's the model class, named UserModel:

class UserModel (val id: String
val name: String,
val contactNumber: String,
val id: String,
val email: String
)

Now, we need to create an interface that will have the HTTP request functions. In this project, we'll only use a GET function that retrieves all the details of users. Here, we're using the GET retrofit annotation to encode details about the parameters and request function.

Here's the code of the UserService interface:

interface UserService {
@GET("/user")
fun getUserList(): Call<List<UserModel>>
}

We'll search the /user endpoint and this will provide a list of user models.