美文网首页
Retrofit 简单使用步骤归纳

Retrofit 简单使用步骤归纳

作者: 处下0512 | 来源:发表于2018-12-06 17:09 被阅读5次

生活太快,需要总结。

1.根据服务端接口地址创建相应的接口

publicinterfaceGitHubService{

@GET("users/{user}/repos")

Call> listRepos(@Path("user") String user);

}

2.创建生成Retrofit实例的工具类

Retrofit retrofit =newRetrofit.Builder()

.baseUrl("https://api.github.com/")

.build();

3.利用Retrofit实例生成接口实例

GitHubService service = retrofit.create(GitHubService.class);

4.调用接口实例对应方法获取Java数据类

Call> repos = service.listRepos("octocat");

相关文章

网友评论

      本文标题:Retrofit 简单使用步骤归纳

      本文链接:https://www.haomeiwen.com/subject/qreuqxtx.html