Help us understand the problem. What is going on with this article?
![Retrofitを使うときの注意事項やメモ - Qiita](https://cdn-ak-scissors.b.st-hatena.com/image/square/96c981f305fe8a0ee5846d581b2114e568d04ffb/height=288;version=1;width=512/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Fogp-background-1150d8b18a7c15795b701a55ae908f94.png%3Fixlib%3Drb-1.2.2%26w%3D1200%26mark%3Dhttps%253A%252F%252Fqiita-user-contents.imgix.net%252F~text%253Fixlib%253Drb-1.2.2%2526w%253D840%2526h%253D380%2526txt%253DRetrofit%2525E3%252582%252592%2525E4%2525BD%2525BF%2525E3%252581%252586%2525E3%252581%2525A8%2525E3%252581%25258D%2525E3%252581%2525AE%2525E6%2525B3%2525A8%2525E6%252584%25258F%2525E4%2525BA%25258B%2525E9%2525A0%252585%2525E3%252582%252584%2525E3%252583%2525A1%2525E3%252583%2525A2%2526txt-color%253D%252523333%2526txt-font%253DAvenir-Black%2526txt-size%253D54%2526txt-clip%253Dellipsis%2526txt-align%253Dcenter%25252Cmiddle%2526s%253D50b3e25a843d7ed74b7c90ee6ea6d788%26mark-align%3Dcenter%252Cmiddle%26blend%3Dhttps%253A%252F%252Fqiita-user-contents.imgix.net%252F~text%253Fixlib%253Drb-1.2.2%2526w%253D840%2526h%253D500%2526txt%253D%252540yyaammaa%2526txt-color%253D%252523333%2526txt-font%253DAvenir-Black%2526txt-size%253D45%2526txt-align%253Dright%25252Cbottom%2526s%253Dc2d8558a608b6890685df8fe4f4ab8da%26blend-align%3Dcenter%252Cmiddle%26blend-mode%3Dnormal%26s%3D0061106d032914b16f76c3b6327cc51c)
注意: この記事はRetrofit 1を対象に書かれています。現在はRetrofit 2がリリースされておりますので内容的に古いです。また、サンプルで利用したYouTube GData APIはサービスを終了していますので動きません。ストックしてくださる方がまだいらっしゃるのでいずれ更新したいと思いますm(_ _)m 調べ物をしていたらたまたまRetrofitというRESTライブラリを見つけたので使ってみました。(okHttpというSPDY対応のライブラリも面白そうなんで後日試してみる予定) とりあえずYouTubeのGData APIから動画の検索結果を持ってくる実装を作ってみました。 ソースはGitHubにうpしてます。 https://github.com/tsuyosh/RetrofitExamples YouTube GData APIにアクセスするために以下の様なインターフェー
レスポンス用のオブジェクトを生成 jsonschema2pojoを利用してjsonから生成 ※基本的には、Source typeはJSON、Annotation styleはNoneでOK 注意!! レスポンスパラメータがスネークケースだと自動変換してくれないので、 サーバ側で返すパラメータはキャメルにしておきましょう。 各部実装 ちょっと長いですが、今回はObserverパターンを利用して汎用的に使えるコールバックも併せて定義しています。 一度作っておくとあとで非常に楽になります。 まずはマニフェスト <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test.hoge.hogehoge" > <!
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/") .build(); GitHubService service = retrofit.create(GitHubServ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く