Hi, I need to make some api calls in my android ap...
# android
k
Hi, I need to make some api calls in my android app and i waant to know how can i do so with kotlin, any library suggestions?
r
retrofit
k
can you provide any link to that
also I heard about volley so out of two which one is more preferred and why?
r
I would say retrofit 2, its much cleaner and easier to use lol. Besides who uses volley in 2018 lol.
k
ok thanks alot
is there official documentation on using retrofit2 with kotlin or is it only available with java
i mean the documentation
r
if you don’t support for HTTP PATCH, I’ll suggest Fuel
it works great with Kotlin, it feels more idiomatic, my only issue was the lack of support for HTTP PATCH
g
There is no difference between usage Retrofit on Java and Kotlin, exactly the same. You can just convert Java sample to Kotlin if you not familiar with Kotlin yet
One can say opposite. Retrofit interface definition much more idiomatic than builder-like API of Fuel. Fuel useful if you have a few requests and doesn't require configuration, but if you want to implement many methods and if you want to do that in abstract way (allow to change endpoint, auth strategy, mock for tests etc), than Retrofit looks for me much better alternative. But Fuel good as simple and configuration free option
k
Thanks @gildor
r
that’s a good point Andrey, I didn’t suffer from that because I implemented a layer of abstraction that was helping me with Mocks, changing endpoints (I need to support multiple even for the same resources), and everything was great until I had to use an http patch method when the server didn’t support
X-HTTP-Method-Override: PATCH
, so I just switched the library to Retrofit and thanks to that layer of abstraction that I build, it was a 2 hours task
but during the transformation to Retrofit I felt I jumped 12 years back to use a similar to Struts api idioms with Retrofit, isn’t so Kotlin idiomatic as you might think, maybe for Java/Android is way better and I could second that 🙂
to be honest that was the first reason I used Fuel instead of Retrofit, to try something more in a Kotlin way, but then I switched back to Retrofit after 2 days trying to generate an HttpClient with support for Patch and connect that to Fuel, in this case the more robust library won, but I’m willing to give a chance to other libraries in the future
g
I implemented a layer of abstraction that was helping me with Mocks, changing endpoints
Yes, but with Retrofit API you get this by default. Very abstract way. Abstraction over request and even response
maybe for Java/Android is way better
What do you mean? Some people hate annotations and such way to define API, but for me it’s the same as defining any other interface. And in 95% cases you write less code with Retrofit and have much more readable and maintainable API definition. I would like to see “more kotlin way” aka “based on dsl” library, but Fuel is just like any other builder-based rest library (check for example Unirest for Java, very similar to Fuel). For example I can imagine something like Retrofit, where you use dsl instead of annotations, but even in this case you need additional abstraction layer, it’s hard to compete with automatic creation of proxy classes