Retrofit

适用于Android和Java的类型安全的HTTP客户端。(A type-safe HTTP client for Android and Java.)

Github星跟踪图

适用于Android和Java的类型安全的HTTP客户端。Retrofit 将您的 HTTP API 转换为 Java 接口。\r\n

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

Retrofit类生成GitHubService接口的实现。
\r\n

Retrofit retrofit = new Retrofit.Builder()\r\n    .baseUrl("https://api.github.com/")\r\n    .build();\r\nGitHubService service = retrofit.create(GitHubService.class);\r\n

来自创建的GitHubService的每个 call 都可以向远程Web服务器发送同步或异步HTTP请求。\r\n

Call<List<Repo>> repos = service.listRepos("octocat");\r\n

使用 annotations (注解)来描述HTTP请求:\r\n

    \r\n\t
  • URL参数替换和查询参数支持
  • \r\n\t
  • 对象转换为请求正文(例如,JSON,协议缓冲区)
  • \r\n\t
  • 多部分请求正文和文件上传
  • \r\n

主要指标

概览
名称与所有者square/retrofit
主编程语言HTML
编程语言Shell (语言数: 7)
平台
许可证Apache License 2.0
所有者活动
创建于2010-09-07 05:39:43
推送于2025-10-31 23:26:27
最后一次提交
发布数58
最新版本名称3.0.0 (发布于 2025-05-16 00:27:16)
第一版名称0.6.0-rc1 (发布于 2012-06-14 03:30:22)
用户参与
星数43.8k
关注者数1.5k
派生数7.3k
提交数2.7k
已启用问题?
问题数2751
打开的问题数127
拉请求数1250
打开的拉请求数33
关闭的拉请求数396
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?

Retrofit

Type-safe HTTP client for Android and Java by Square, Inc.

For more information please see the website.

Download

Download the latest JAR or grab from Maven central at the coordinates com.squareup.retrofit2:retrofit:2.7.1.

Snapshots of the development version are available in Sonatype's snapshots repository.

Retrofit requires at minimum Java 8+ or Android API 21+.

R8 / ProGuard

If you are using R8 the shrinking and obfuscation rules are included automatically.

ProGuard users must manually add the options from
this file.
(Note: You might also need rules for OkHttp and Okio which are dependencies of this library)

License

Copyright 2013 Square, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.