Retrofit 2.1 example showing get response

Step 1 : create Rest Interface like below attached find it(watch only).

Step 2 : create MainActivity like below attached find it.

Step 3: create gradle add it and (Sync) it.

Step 4 : create pojo classes using json example as shown below.

Note: use jsonSchematopojo site to generae model , then name the first class is "Example".

over.

step:1:

Gson gson = new Gson();

Retrofit retrofit = new Retrofit.Builder()

.baseUrl("http://drapp.sciensdemos.in/index.php/")

.addConverterFactory(GsonConverterFactory.create(gson))

.build();

ServiceOperations serviceOperations = retrofit.create(ServiceOperations.class);

Call<Example> call = serviceOperations.all();

Step 2:

public class MainActivity extends AppCompatActivity{

private final String BASEURL = "http://drapp.------demos.in/index.php/";

Gson gson = new Gson();

Retrofit retrofit = new Retrofit.Builder()

.baseUrl("http://drapp.sciensdemos.in/index.php/")

.addConverterFactory(GsonConverterFactory.create(gson))

.build();

ServiceOperations serviceOperations = retrofit.create(ServiceOperations.class);

Call<Example> call = serviceOperations.all();

call.enqueue(new Callback<Example>() {

@Override

public void onResponse(Call<Example> call, Response<Example> response) {

Log.d("Lokesh",""+response.message());

Toast.makeText(MainActivity.this, response.isSuccessful()+"", Toast.LENGTH_SHORT).show();

Example examples =response.body();

if(examples == null){

Toast.makeText(MainActivity.this, "it is null", Toast.LENGTH_SHORT).show();

}else {

Toast.makeText(MainActivity.this, examples.getData().get(0).getSpecializationName(), Toast.LENGTH_SHORT).show();

}

}

@Override

public void onFailure(Call<Example> call, Throwable t) {

}

});

}

Step 3:

compile 'com.squareup.retrofit2:retrofit:2.1.0'

compile 'com.squareup.retrofit2:converter-gson:2.1.0'

Step 4 :

{

"status": "sucess",

"data": [

{

"specialization_id": "1",

"specialization_name": "Physical Medicine and Rehabilitation"

} ],

"statusCode": 200

}

out put :

true,

Physical Medicine and Rehabilitation shown toast.