简体   繁体   中英

Android Development and retrofit

My Question is simple i want to retrieve my github repos with the help github api using retrofit in android, So i am little confuse how to pass my github username to url i have tried but it give me error message. This is my webservice URL for retrieving my github repos : https://api.github.com/users/mshahzaib374/repos . Here you can see my username is mshahzaib374 , So how can i pass my username to url as parameter. I hope you understand my question, I am attaching code snippets and error screen please see it, Thanks for advance.

Retrofit homepage contains sample code that very similar to what you want:

public interface GitHubService {
  @GET("users/{user}/repos")
  Call<List<Repo>> listRepos(@Path("user") String user);
}

So, to insert username in URL you have to substitute part of URL with some name in curly braces and add corresponding parameter to method marked with @Path("<your parameter name>") annotation.

You can make a GET API call like this

GET /users/:username/repos

Check this out the official GIT api documentation.

Hope it helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM