Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Retrofit
StackOverflowGitHub

Introduction

Retrofit turns your HTTP API into a Java (or Kotlin) interface.

publicinterfaceGitHubService {
@GET("users/{user}/repos")
Call<List<Repo>>listRepos(@Path("user")Stringuser);
}

TheRetrofit class generates an implementation of theGitHubService interface.

Retrofitretrofit=new Retrofit.Builder()
.baseUrl("https://api.github.com")
.build();
GitHubServiceservice=retrofit.create(GitHubService.class);

EachCall from the createdGitHubService can make synchronous or asynchronous HTTP requests to the remote webserver.

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

Use annotations to describe the HTTP request on each interface method:

  • URL parameter replacement and query parameter support
  • Object conversion to request body (e.g., JSON, protocol buffers)
  • Multipart request body and file upload

[8]ページ先頭

©2009-2025 Movatter.jp