Hey everyone, I have pre existing Android applicat...
# ktor
v
Hey everyone, I have pre existing Android application using
OKHTTP
client with some`interceptors` and
authenticator
and iOS application using
alamofire
with
interceptors
.Both projects are huge in size. Now I want to use KMM for new api client. So How can I use these 2 http client through Ktor. I don't want to write from scratch in KMM module. Any suggestion?
s
You can’t use them inside Ktor, since the client logic will need to be written in common code.
v
Do i need to use write from scratch?
d
Why do you want three API "clients"? OKHTTP, alamofire, AND Ktor?
You can't use the native routines through Ktor unless you wrap them, but even then I'm not sure how that would work.
The best thing to do would be to not worry about the existing stuff and write your new API handler via KMM/Ktor. You could slowly move common routines from your "legacy" API code and add them to the Ktor code. Obviously, that means re-writing them. But if you do it incrementally, the burden shouldn't be too bad.
v
I don't want to change my previous retrofit and alamofire code because my project is huge in size. Now I want to use KMM, and Ktor is way to connect both platform. But in my retrofit and alomofire has interceptor and authenticator. So I want same behaviour in ktor client. That's why I asked is there a way to use existing in ktor or not
yeah I didn't find the way to connect intercepter
d
Are you asking if you can use your existing implementation in KMM/Ktor, or are you asking if there are interceptors and authenticators in Ktor?
I may have misunderstood the question.
v
I am asking can I use my existing implementation in kmm/ktor or not ?
I know that interceptor and authenticator are available in ktor
s
You’d need to reimplement everything in KTOR. You can try to do this in phases if your project allows you to do that, for example first do all unauthenticated calls then add the one that require authentication. Also remember that some of the custom interceptors/authenticators might not be needed in KTOR, as it has lots of features/plugins.
v
Ok that's great
a
You can configure the OkHttp engine to use your existing interceptors (see an example here). Unfortunately, for
alamofire
this not gonna work.
v
so I need to write logic in ios module?
a
Yes.