RetroFit
A Simple, Powerful, Lightweight, REST client for Android from Square
General Pattern
JSON is deserialized with Google GSON library. Naming can be overridden with the @SerializedName annotation
General Pattern
2. Create a client interface to define methods
Inline Variables can also be defined as follows:
// Produces a url like "foo/idValue/bar?category=categoryValue".� @GET("foo/{id}/bar")� void getWithPathParam(@Name("id") String id, @Name("category") String category, Callback<MyJsonObj> callback);
Async | Sync |
void getThings(@Name("param") String param, Callback<List<Thing>> callback); | List<Thing> getThings(@Name("param") String param); |
General Pattern
3. Use RestAdapter to build the service client:
MyRestInterface client = mRestAdapter.create(MyRestInterface.class);
Keep in mind that this client object is intended to be a long-lived object. You should not create it for every request. In the RetroFitTwitterClient example, a Singleton is used to manage the client instances. It would be best if these client objects were injected via a dependency injection framework like Dagger.
General Pattern
4. Execute requests on the service client:
List<Tweet> tweets = client.getUserTweets(userName, "1");
Strengths
Weaknesses
Installation options
OR
Code
https://github.com/dustin-graham/ucad_twitter_retrofit_sample