Call api using Volley library Demo
- 1 Call rest Api using Volley in Android
- 2 Dependencies
- 3 Structure for Volley Api request
- 4 Top 10 free Android libraries for app development in android studio
- 5 Recyclerview to display List
- 6 Calling Tmdb Api
- 7 Adding the load more or infinite scrollview to recyclerview.
- 8 https://github.com/askfortricks/VolleyWithGsonDemo
Call rest Api using Volley in Android
The very basic requirement in developing the Android application is “Api Integration” and fetch the details. For calling the Api we need android networking library to interact with the web services and get the response from Api.
One such library is Volley which is developed by Google to handle Api calls.
Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster. Volley is available on GitHub.
To know more about Volley, go here.
Our Post is divided into five parts, we will call https://www.themoviedb.org/
Its a collection of apis , for our demo we are fetching the list of popular movies from tmdb and display in recyclerview.
We need to sign up and get the api_key before we can call any Api.
We need to add below dependencies in app->build.gradle
//recyclerview to show list
Structure for Volley Api request
WebApiRequest.java class is common class to call apis. We just have to create instance of the class and call its appropriate constructor to initialize our Volley api call.
For future enhancement we have added different parameters if we need to call the apis with custom headers and parameters.
Recyclerview to display List
Here we will call TOP_RATED movie Api in the call method mentioned in the MovieListingActivity.java to fetch the results.
Most important method is ReqSuccessListener which will handle the callback if api returns the results.
ReqErrorListener method will handle any server error if any in the response. If server returned unexpected response then this method will handle it.
Calling Tmdb Api
Adding the load more or infinite scrollview to recyclerview.
We have attached a scroll listener as always we need to add endless scroll or infinite scroll to load the results. In web format we call it paging based on the number of results. Say we need 20 results in one api call. And then again next 20 sequentially.
This will be used by you in any application or projects.
For Complete Demo of Volley using Gson find the source codes in below project.
Ravi Yadav is an Android developer whose passion is to develop Android applications and sharing his work. He loves to post the tutorials which he created while learning any new latest technology topic.He loves to share about the latest technology happenings and other tricks that will be helpful for readers of Askfortricks.