Retrofit

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

Github stars Tracking Chart

适用于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

Main metrics

Overview
Name With Ownersquare/retrofit
Primary LanguageHTML
Program languageShell (Language Count: 7)
Platform
License:Apache License 2.0
所有者活动
Created At2010-09-06 21:39:43
Pushed At2025-06-07 12:15:33
Last Commit At
Release Count58
Last Release Name3.0.0 (Posted on 2025-05-15 12:27:16)
First Release Name0.6.0-rc1 (Posted on 2012-06-13 12:30:22)
用户参与
Stargazers Count43.5k
Watchers Count1.5k
Fork Count7.3k
Commits Count2.5k
Has Issues Enabled
Issues Count2743
Issue Open Count127
Pull Requests Count1118
Pull Requests Open Count34
Pull Requests Close Count388
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

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.