https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
r

Rita Okonkwo

04/30/2021, 7:45 AM
Hello everyone, I am working with KMM & KTOR to post data to an API. However , when the post request is successful, it returns a set of API-specific headers. I am supposed to use one of the header information to make another request. So , I made the POST request to return an HttpResponse. However, AS shows this error when trying to make the post request in my main activity in android studio. Please any idea on how I can fix it? Thank you
Update: So I tried to access the http response from shared module instead and the error is gone. There’s a new error though. I tried running the app and it says serializer for my model classes isn’t found. But I installed the serialization dependencies and included the necessary annotations
t

Tomasz Krakowiak

04/30/2021, 11:54 AM
@Rita Okonkwo Show the code, where you get the serializer error, someone will figure it out : )
👍 1
m

Martins Iroka

04/30/2021, 12:24 PM
Did you add the serialization classpath? I had error similar to this. I realized I didn't add the classpath in my project gradle.
👍 1
c

Cicero

04/30/2021, 12:59 PM
The thing is that you can’t import this HttpResponse in AS. You can handle it in the common module. On thing that is really cool is to handle it using the “Railway System” (which is basically an Either approach) or an “Either” approach in the common module.
👍 1
This gets a little tricky to handle if you are usng this code in swift too
👍 1
But then it is another question
👍 1
It’s no so much you can’t but this is not imported with the ktor android module you would need to import this dependency some other way
👍 1
r

Rita Okonkwo

05/01/2021, 8:14 PM
Thank you all for your responses, I really appreciate 😁
I realized that some data classes didn’t have the serializable annotation, that’s why I was getting the serializer error
I’ve been able to fix it now by including the serializable annotation
Thank you all once again
👍🏿 1
👍🏽 1
c

Cicero

05/01/2021, 11:06 PM
But you can use “HttpResponse” in your android project? Could you share the dependencies in your android sourceSet? I would really appreciate to use this class to resolve responses
Also, if you could share the import of your HttpResponse in the android project and common it would be very cool too
r

Rita Okonkwo

05/07/2021, 11:03 AM
Hello @Cicero , I wasn’t able to use HttpResponse in my android project . Used it in the shared folder (commonMain) instead :)
👌🏽 1
c

Cicero

05/07/2021, 11:10 AM
That’s what I imagined, thanks
2 Views