https://kotlinlang.org logo
#ktor
Title
# ktor
c

cisimon7

11/14/2020, 9:48 PM
I wonder what I am doing wrong, but I have been unable to make a simple request from UI (kotlin React) to Ktor backend using the HttpClient. Any pointer to an example please, preferably one done with Ktor version 1.4.0 and above
d

df

11/14/2020, 9:55 PM
c

cisimon7

11/14/2020, 10:51 PM
Thank you for the response. I am able to create the test and everything works ok, but when it comes to connecting to the ktor server backend, it seems the request doesn't reach it at all. testing the ktor server separately works, and also testing the react front end separately works as well. which brings me think it must be the http client. Sample project in repository below: https://github.com/cisimon7/KtorClient
d

df

11/14/2020, 11:04 PM
never worked with multi-platform projects.. how do i start the whole thing 😉
c

cisimon7

11/14/2020, 11:15 PM
Here: https://play.kotlinlang.org/hands-on/Full%20Stack%20Web%20App%20with%20Kotlin%20Multiplatform/01_Introduction I am currently going through this now even, maybe I'll find my mistake
d

df

11/14/2020, 11:22 PM
but the output.js is build on your computer? asking because just running the app locally produces a 404 on the output.js (for me)
seems working to me
c

cisimon7

11/14/2020, 11:46 PM
Yeah, that is another strange thing. A get request to ktor backend works on app start up. But I have been unable to send a request from the UI (web page on display). For example, inputting the letter B, and clicking on the Find button should print a name ("Boruto ....") in the console
d

df

11/14/2020, 11:51 PM
the post request fails and throws an exception
easy to verify if you wrap your http.post call in a try/catch block and return sth. like Person("foo", 11)
i guess you don't see the exception because the request is executed in the background
c

cisimon7

11/15/2020, 12:12 AM
Indeed I wasn't seeing the exception. Used try catch on the request as you said and I was able to see the error message. I was closing the client after the first call to the server, that was the cause of my problems. Resolved now. Thank you very much
d

df

11/15/2020, 12:16 AM
hehe
the client_.use { } thingy?
c

cisimon7

11/15/2020, 12:17 AM
yes, exactly 😁
3 Views