Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Retrofit Tutorial

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 726
    Comment on it

    Here is a new simple and easy option for making network requests. In comparison to volley this one is bit fast following is the test result that depicts the same.

    alt text

    This awesome library is Retrofit multiple versions are available as the development is done since lot of time, at the time of writing this blog its current version is 2.0.

    While working with retrofit we need to create three classes

    Modal Class - where the data is stored in its corresponding variable received from network. Interface - An interface is required that will manage the get, post. etc requests. RestAdapter Class - This is the RestClient class.

    As mentioned earlier using this library is pretty simple

    Add this library to your project by adding following line into your compile statement

    compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'

    and make the request as follow.

    Retrofit retrofit = new Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create()) .build();
    service = retrofit.create(APIService.class);

    The best part is you need not to use the Gson module as the only because with retrofit you can use any of the following libraries to parse your response.

    Gson Jackson Moshi Protobuf Wire Simple XML

    and most importantly we can create our own converter by using Converter.Factory interface. (This will be discussed in my next blog).

    Retrofit Tutorial

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: