Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile-time safe Ktorfit #187

Closed
esafirm opened this issue Mar 5, 2023 · 4 comments
Closed

Compile-time safe Ktorfit #187

esafirm opened this issue Mar 5, 2023 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@esafirm
Copy link

esafirm commented Mar 5, 2023

Hi @Foso, great library! I was thinking of creating something like this but luckily found this first.

My concern with this is that

  1. There's a lack of a compile-time safe in the library,create() can throw a runtime error if the compiler plugin is not applied
  2. The needs to add an extra Gradle plugin to create the first condition

I assume you chose this design to mimic what Retrofit have, but maybe we can make this better by not doing so?

What I have in mind is to have a generation like Dagger and move the creation to the impl instead

interface  ExampleApi { ... }

// Instead of _ExampleApiImpl
val api = KtorfitExampleApi.create(ktorfit)

Let me know what you think.

Cheers!

@esafirm esafirm added the enhancement New feature or request label Mar 5, 2023
@Foso
Copy link
Owner

Foso commented Mar 5, 2023

Hi @esafirm , thank you. I understand your concerns.
Yes, it was done this was way to mimic Retrofit.

It`s not really documented, but Ktorfit also generates an extension function on Ktorfit for every generated interface implementation.
So you can already do

val api = ktorfit.createExampleApi()

The only issue with that is, that you can use this function only in platform specific modules, not in a common module. This is because KSP only generates code to the platform specific modules. If you just want to use it in Android projects, it should work this way and you don`t need the gradle/compiler plugin

@esafirm
Copy link
Author

esafirm commented Mar 7, 2023

Ah yes, I forgot about that issue.

I can see that until google/ksp#567 is resolved, the current approach might be a good solution.

@Foso
Copy link
Owner

Foso commented Mar 15, 2023

Till we find a better solution we will keep the compiler plugin. I would like to find a solution where it's not needed anymore

@Foso Foso added this to the 2.0.0 milestone May 28, 2024
@Foso
Copy link
Owner

Foso commented May 28, 2024

@esafirm With Ktorfit 2.0.0 I found a way to make the extension functions usable from commonMain. The compiler plugin is for now still part of the project, but when you use the extension functions, the compiler plugin will not be active.

@Foso Foso closed this as completed May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants