Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

How to make multiple requests via OKHTTP

I'm doing a project which takes data from an API and displays on the phone. But the API has many different URLs and I need to use 3 of them to get all the data that I want. Do I need have multiple uses of OkHTTP or can I use the same one for everything.

1 Answer

If there are only small differences between the URLs, you can create a method that makes the OKHTTP call that has the "different" part of each URL as the parameter, which you can then fill in that part of the URL.

Then all you'd have to do is call that method 3 times with the different parameters