r

    Rita Okonkwo

    1 year ago
    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
    Tomasz Krakowiak

    Tomasz Krakowiak

    1 year ago
    @Rita Okonkwo Show the code, where you get the serializer error, someone will figure it out : )
    Martins Iroka

    Martins Iroka

    1 year ago
    Did you add the serialization classpath? I had error similar to this. I realized I didn't add the classpath in my project gradle.
    Cicero

    Cicero

    1 year ago
    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.
    This gets a little tricky to handle if you are usng this code in swift too
    But then it is another question
    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
    r

    Rita Okonkwo

    1 year ago
    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
    Cicero

    Cicero

    1 year ago
    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

    1 year ago
    Hello @Cicero , I wasn’t able to use HttpResponse in my android project . Used it in the shared folder (commonMain) instead 😃
    Cicero

    Cicero

    1 year ago
    That’s what I imagined, thanks