Retrofit源码分析 (四. Retrofit 官网说明,Copy)

来源:互联网 发布:s7总决赛现场数据 编辑:程序博客网 时间:2024/05/17 21:47

使用retrofit官网

Introduction
Retrofit turns your HTTP API into a Java interface.

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

The Retrofit class generates an implementation of the GitHubService interface.

Retrofit retrofit = new Retrofit.Builder()    .baseUrl("https://api.github.com")    .addConverterFactory(GsonConverterFactory.create())    .build();

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

Each Call from the created GitHubService can make a synchronous or asynchronous HTTP request to the remote webserver.

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

Use annotations to describe the HTTP request:

URL parameter replacement and query parameter support

Object conversion to request body (e.g., JSON, protocol buffers)

Multipart request body and file upload

原创粉丝点击