18

With Kotlin native giving us the promise of cross platform development and native executables, is there an equivalent of the Java lib Retrofit for Kotlin Native? IOW is there a pure Kotlin networking library that makes creating http client code simple, and quick as Retrofit does for Java?

Patrick Jackson
  • 18,766
  • 22
  • 81
  • 141

5 Answers5

13

I've just published an example project where I use ktor-client in a Kotlin project with both iOS and Android.

https://github.com/thoutbeckers/kotlin-mpp-example

( note: this example is now very out of date, but in the meanwhile ktor has progressed tremendously, and also have a multiplatform sample: https://ktor.io/learn/ )

thoutbeckers
  • 2,599
  • 22
  • 24
  • 2
    This does seem like the best solution currently. However, I would not say it is as simple and as few lines of code as Retrofit. Also there appears to be some difficulty with Serialization of certain types (root lists for example). – Patrick Jackson Oct 24 '18 at 15:06
  • Is this better than Retrofit? – IgorGanapolsky Apr 02 '19 at 21:57
2

At the moment wrapping some C library, like CURL is the best option. See https://github.com/JetBrains/kotlinconf-spinner/tree/master/kurl for example of how it could be done.

In this example we provide interoperability library matching CURL directly, and more Kotlin'ish wrapper, which calls (somewhat confusing) CURL APIs in more easy to use manner.

Nikolay Igotti
  • 580
  • 2
  • 7
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/18887451) – Abhishek kumar Feb 21 '18 at 10:51
  • @Abhishekkumar Which has happened now. Link is not working. – Chintan Soni Oct 10 '18 at 13:37
1

Ktorfit looks like what you are looking for (a very young - but IMHO promising - project):

Ktorfit is a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

Gilad Bar Orion
  • 543
  • 6
  • 14
0

I've made a library just for this purpose, actually I'm using it in some projects. https://github.com/eduayuso/konet.

On the other hand you have an alternative which inspired me to make this library, but it not exactly what you want: https://github.com/icerockdev/moko-network.

Edu
  • 810
  • 7
  • 11
-2

There is a nice and easy to use http networking library called "fuel" which is written in Kotlin. https://github.com/kittinunf/Fuel It also supports RxJava and coroutines.

  • 1
    Fuel is not a Kotlin Multiplatform library, thus it doesn't support Kotlin Native – Volo Mar 26 '20 at 17:18