Questions tagged [retrofit]

Retrofit is a type-safe REST client for Android and Java by Square, Inc.

Retrofit turns REST API into a Java interface.

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

The RestAdapter class generates an implementation of the GitHubService interface.

RestAdapter restAdapter = new RestAdapter.Builder()
   .setEndpoint("https://api.github.com")
   .build();

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

Each call on the generated GitHubService makes an HTTP request to the remote webserver.

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

Annotations are used 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

The library is open sourced under Apache 2.0 license.

References

8574 questions
3
votes
1 answer

java - which exception fits best an Unauthorized HTTP response (401)?

In java (Android), is there a standard exception I should throw to signal a 401 Unauthorized response from a server?
ticofab
  • 7,551
  • 13
  • 49
  • 90
3
votes
3 answers

Issue with Retrofit and Simple - attempt at making a RSS Reader for Android

I'm trying to download XML data with Retrofit and parse it with Simple and then load it into a ListView. Unfortunately downloaded data won't appear on screen. Could someone tell me where is the problem, please? This is my model: @Root(name =…
M. Underhill
  • 105
  • 1
  • 10
3
votes
4 answers

JSON Parsing with Retrofit

I started using Retrofit recently. I don't know much about it. I have googled this issue and no answers suite my problem. This is JSON response { "results": [ { "description_eng": "This is second time testing", "img_url": "-", …
Ye Min Htut
  • 2,904
  • 15
  • 28
3
votes
1 answer

In gson/retrofit, is there a built-in way to handle dates of varying formats?

The api I'm currently using returns dates (for the sake of this question, dates and datetimes are the same) in the form of "yyyy-MM-dd" and also in the typical ISO8601 format "2012-06-08T12:27:29.000-04:00" How do you "cleanly" set up GSON to handle…
loeschg
  • 29,961
  • 26
  • 97
  • 150
3
votes
1 answer

Understanding streams of data and multiple subscribers (using retrofit)

Say I have 2 Observables (A & B) that are essentially network calls (using Retrofit to give context). The current flow of the app is as follows: A & B are kicked off at about the same time (asynchronously). B is executed 0 or more times on user…
loeschg
  • 29,961
  • 26
  • 97
  • 150
3
votes
0 answers

OkHttp is not caching responses on Android

I am using retrofit 1.8.0, okhttp 2.1.0 and okhttp-urlconnection 2.1.0, I want to cache the responses I get from server and use them when there is no internet connection, this is my code: RequestInterceptor requestInterceptor = new…
khaled sultan
  • 75
  • 1
  • 4
3
votes
2 answers

RetrofitError Exception

I have the following code... public interface GithubService { @GET("/repos/{owner}/{repo}/contributors") public List contributors(@Path("owner") String owner, @Path("repo") String…
Amaury Esparza
  • 1,028
  • 2
  • 12
  • 18
3
votes
2 answers

HTTP vs HTTPS requests with Retrofit

I'm working on REST API client for Android using Retrofit. Some of the use something like this http://my.backend.com and others use https://my.backend.com. The way I found is to create two separate interfaces and build two RestAdapters with…
oleg.semen
  • 2,901
  • 2
  • 28
  • 56
3
votes
2 answers

raw string in post request body using retrofit

i want to send user:user in the post request body. I am using retrofit lib. please suggest me. I have tried already like this @POST(/login) void login(@BODY String s,Callback) And called this…
Vinod Kumar
  • 137
  • 1
  • 11
3
votes
1 answer

spiceManager.isDataInCache is empty/null in Fragment

I would like to ask assistance for my error. I used robospice-retrofit for my api and I want to get the cache. In my other sample program the I could get the cache and the value but when i used it in the fragment, I always have a null value of my…
user4144348
  • 313
  • 3
  • 8
3
votes
1 answer

Android self signed certificate with local lan IP

I'm creating an app to control a store, i'm trying to use a local server (192.168.0.56) through an open wifi. There's a way to my app connect to my server using HTTPS and a self signed certificate? I'm using retrofit, if its matter. I tried a lot of…
talski
  • 293
  • 2
  • 11
3
votes
1 answer

gson custom convert json key to string

My server is returning json key-value pair like { "my-name":"name" } I am using retrofit lib. So that gson is converting this to java object. So I created java object like below public class Example{ public String myname; // cannot have…
Vinod Kumar
  • 137
  • 1
  • 11
3
votes
1 answer

Android connection fails if I disable SSLv2/SSLv3 on the HTTPS server

In a Android app (Kitkat 4.4.4 on a Nexus 7) I use the Retrofit REST library to access a HTTPS server which I configured to allow only TLS, but no SSL (to fix the Poodle vulnerability). My Retrofit setup code is simple RetrofitInterface…
mjn
  • 36,362
  • 28
  • 176
  • 378
3
votes
1 answer

Retrofit-like library with disk cache support

I'm using Retrofit library from network calls. Pretty awesome. But I'm missing caching support. I can't using cache on HTTP layer (via Cache headers). Currently, I'm implementing custom caching with ObjectCache, but it's so complicated. It just…
Radim Vaculik
  • 559
  • 4
  • 16
3
votes
3 answers

Retrofit POST request w/ Digest HTTP Authentication: “Cannot retry streamed HTTP body”

I'm trying to implement digest authentication using Retrofit. My first solution sets an implementation of OkHttp's Authenticator on an OkHttpClient: class MyAuthenticator implements Authenticator { private final DigestScheme digestScheme = new…
nucleartide
  • 3,888
  • 4
  • 28
  • 29