title: How to login with retrofit2 using GET method
body: <p>I am using a <strong>API</strong> for <strong>login</strong></p>
  
  <pre><code>http://abc.demoserver.com/API/login.php?username=johndoe&amp;password=123456
  </code></pre>
  
  <p>this <strong>API</strong> is in <strong>GET method</strong></p>
  
  <p>and also using retrofit2 so my code snippet is here.</p>
  
  <p><strong>APIUtils.java</strong></p>
  
  <pre><code>public static final String BASE_URL = "http://abc.demoserver.com/API/";
  
  public static APIService getAPIService() {
      return RetrofitClient.getClient(BASE_URL).create(APIService.class);
  }
  </code></pre>
  
  <p><strong>APIServiceInterface.java</strong></p>
  
  <pre><code>@GET("login.php")
  Call&lt;JsonObject&gt; studentLogin(@Query("username") String username,
                                @Query("password") String password);
  </code></pre>
  
  <p>and my <strong>RetrofitClient.java</strong> is</p>
  
  <pre><code>public class RetrofitClient {
  
  private static Retrofit retrofit = null;
  
  public static Retrofit getClient(String baseUrl) {
      if (retrofit == null) {
          retrofit = new Retrofit.Builder()
                  .baseUrl(baseUrl)
                  .addConverterFactory(GsonConverterFactory.create())
                  .build();
      }
      return retrofit;
    }
  }
  </code></pre>
  
  <p>This gives me response null but when I hit this URL in browser it gives the <code>response</code> in <strong>below format</strong></p>
  
  <pre><code>{
    "details": [
      {
        "ID": "56895",
        "user_login": "johndoe",
        "user_pass": "$P$BPjOjHab\iHVP0/YPOIly.b1",
        "user_email": "abc@xyz.com",
        "user_registered": "2017-02-10 07:28:39",
        "user_status": "0",
        "display_name": "John Doe",
        "instructor": "23",
        "token": "212cde4b85163cbd05962ef",
        "profile_img": "http://abc.demoserver.com/wp-content\/uploads\/avatars\/16895\/165113b6b900b4cf145b84c31.jpg"
      }
    ],
    "status_code": 1,
    "status_description": "Login successful."
  }
  </code></pre>
  
  <p><strong>UPDATED</strong></p>
  
  <p><strong>Call back</strong></p>
  
  <pre><code>public void loginData(String username, String password) {
      final ProgressDialog dialog = new ProgressDialog(this);
      dialog.setMessage("Please wait...");
      dialog.setCancelable(false);
      dialog.show();
  
      apiService.studentLogin(username, password).enqueue(new Callback&lt;JsonObject&gt;() {
          @Override
          public void onResponse(Call&lt;JsonObject&gt; call, Response&lt;JsonObject&gt; response) {
  
              dialog.dismiss();
  
              try {
                  if (response != null) {
                      JSONObject josn = new JSONObject(response.body().toString());
  
                      JSONArray jarray = josn.getJSONArray("details");
                      for (int i = 0; i &lt; jarray.length(); i++) {
  
                          JSONObject jsonObject = jarray.getJSONObject(0);
  
                          user_id = jsonObject.getString("ID");
                          user_name = jsonObject.getString("user_login");
                          user_mail = jsonObject.getString("user_email");
                          user_display_name = jsonObject.getString("display_name");
                          user_registered = jsonObject.getString("user_registered");
                          user_status = jsonObject.getString("user_status");
                          token = jsonObject.getString("token");
                          instructor = jsonObject.getString("instructor");
                          user_pass = jsonObject.getString("user_pass");
                          profile_img = jsonObject.getString("profile_img");
                      }
  
                  }
  
              } catch (Exception e) {
                  e.printStackTrace();
                  Log.e("Exception", e.getMessage());
              }
  
          }
  
          @Override
          public void onFailure(Call&lt;JsonObject&gt; call, Throwable t) {
              Log.e("onFailure", "Unable to get API." + t.getMessage());
              dialog.dismiss();
          }
      });
  }
  </code></pre>
  
  <p>how to call a GET method API in retrofit2</p>