Day 2 : Kotlin Api Call using Volley

1550707200000 Kotlin

by Start Bootstrap


Api call using Volley is very much easier. Yes, code is drastically reduced here

Just add the dependency

implementation 'com.android.volley:volley:1.1.1' // migrating to implementation is important

And here we do the GET Method

val queue = Volley.newRequestQueue(this);
val stringRequest = StringRequest(Request.Method.GET, "http://sulthanallaudeen.com/api/v1/ping",
Response.Listener<String> { response ->
Toast.makeText(this@LoginActivity, response, Toast.LENGTH_SHORT).show();
},
Response.ErrorListener {
Toast.makeText(this@LoginActivity, "Error in API Request", Toast.LENGTH_SHORT).show();
})
queue.add(stringRequest);

And this makes entire process easy !!