title: Retrofit: How to send value to REST API and check if it exists?
body: <p>First of all I'm playing with Retrofit for the first time in Kotlin Android. </p>
  
  <p><strong>So the Logic i want is like this:</strong></p>
  
  <ol>
  <li>I want send a <strong>username</strong> to the Rest API.</li>
  <li>Then check if it is exists or not.</li>
  <li>if it exists I want to make a Toast message saying <strong>true</strong> if it does not exist <strong>False</strong>.</li>
  </ol>
  
  <p>So, I have this JSON in this URL:<code>https://jsonplaceholder.typicode.com/users</code>:</p>
  
  <pre><code>[
    {
      "id": 1,
      "name": "Leanne Graham",
      "username": "Bret",
      "email": "Sincere@april.biz"
    },
    {
      "id": 2,
      "name": "Ervin Howell",
      "username": "Antonette",
      "email": "Shanna@melissa.tv"
    },
    {
      "id": 3,
      "name": "Clementine Bauch",
      "username": "Samantha",
      "email": "Nathan@yesenia.net"
    }
  ]
  </code></pre>
  
  <p>So let me walk through the content of my code using Retrofit</p>
  
  <p><strong>Model.class</strong> </p>
  
  <pre><code>class FakeUserModel {
      @Expose
      @SerializedName("username")
      val username: String = ""
  }
  </code></pre>
  
  <p><strong>Retrofit Api Client</strong> class</p>
  
  <pre><code>object FakeUserApiClient {
    var BASE_URL:String="https://jsonplaceholder.typicode.com/"
    val getFakeUserClient: ApiInterface
      get() {
  
          val gson = GsonBuilder()
              .setLenient()
              .create()
          val interceptor = HttpLoggingInterceptor()
          interceptor.setLevel(HttpLoggingInterceptor.Level.BODY)
  
          val client = OkHttpClient.Builder()
              .addInterceptor(interceptor)
              .build()
  
          val retrofit = Retrofit.Builder()
              .baseUrl(BASE_URL)
              .client(client)
              .addConverterFactory(GsonConverterFactory.create(gson))
              .build()
  
          return retrofit.create(ApiInterface::class.java)
      }
  }
  </code></pre>
  
  <p>And this ApiInterface to demonstrate the fucntion to you are using to send data to the server:</p>
  
  <p><strong>Api Interface</strong></p>
  
  <pre><code>interface ApiInterface {
       @FormUrlEncoded
       @POST("users")
       fun check( @Field("username") username:String ): Call&lt;FakeUserModel&gt;
  }
  </code></pre>
  
  <p>So finally, in the Activity I want to receive the response telling me if it exists or not...</p>
  
  <p><strong>Activity class</strong></p>
  
  <pre><code>checkButton.setOnClickListener {
      val username = userName.text.toString().trim()
  
      FakeUserApiClient.getFakeUserClient.check(username)
          .enqueue(object : Callback&lt;FakeUserModel&gt;{
              override fun onFailure(call: retrofit2.Call&lt;FakeUserModel&gt;, t: Throwable) {
                  Toast.makeText(applicationContext, t.message, Toast.LENGTH_LONG).show()
              }
  
              override fun onResponse(
                  call: retrofit2.Call&lt;FakeUserModel&gt;,
                  response: Response&lt;FakeUserModel&gt;
              ) {
                  if (response != null) {
                      Toast.makeText(applicationContext, "true", Toast.LENGTH_LONG).show()
                  }else{
                      Toast.makeText(applicationContext, "false", Toast.LENGTH_LONG).show()
                  }
              }
  
          })
  }
  </code></pre>
  
  <p>When I execute the app it always saying <code>true</code>, even if the username I have passed is not on the JSON... 
  So, guys is there a problem in my code? What did I missed? Is there a better way to do it? Thanks!</p>