Creating a model

We will use the GitHub API. You can check all the REST API URLs at https://api.github.com/. We will use the simplest API, which has no security issues. We will show the list of a user's repositories. The API is https://api.github.com/users/{user}/repos. You need a GET HTTP function with a username parameter.

The following screenshot shows the output of the REST API:

The left-hand side of the preceding screenshot shows part of the content of a repo and the right-hand side is the collapsed total repo list.

So, according to the API, we will create a user model for the client side. Here is the model class named GitHubUserModel.ktwhere we will show only the name of the list of all the repos:

class GitHubUserModel {
val name: String? = null
}

Create an interface that will have the HTTP request functions. In this projectwe will only use a GET function that retrieves all the details of the users. Here, we are using the GET Retrofit annotation to encode details about the parameters and the request function. For this function, our endpoint is /users/{user}/repos, where you need to add a parameter of the userName and it will provide a list of UserModel

Here is the code of the GithubService interface:

interface GithubService {
@GET("/users/{user}/repos")
fun reposOfUser(@Path("user") user: String): Call<List<GitHubUserModel>>
}
..................Content has been hidden....................

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