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

Jim

10/05/2021, 7:11 PM
Could someone help me find an example of a ktor client that interacts with a versioned rest api?
t

turansky

10/06/2021, 2:54 AM
Do you need nested routes?
j

Jim

10/06/2021, 3:41 AM
I think that's a server side thing, I'm looking for the client side equivalent I think 🤔
t

turansky

10/06/2021, 10:02 AM
For React? Which framework?
j

Jim

10/07/2021, 12:11 AM
Just a hand written ktor client
I probably should just wrap ktor http client and have the path change the version of my api based on some kind of session
t

turansky

10/07/2021, 12:36 AM
No SPA?
j

Jim

10/07/2021, 12:46 AM
The kmp js target will be a react component library for the main TS SPA
a

Aleksei Tirman [JB]

10/12/2021, 11:42 AM
You can use URLBuilder to create various URLs reusing common components. Here is an example:
Copy code
val v1 = listOf("v1")
val users = v1 + listOf("users")
val baseUrl = URLBuilder("<https://mywebsite.com/>")

println(baseUrl.build())
println(URLBuilder(baseUrl).apply { path(v1) }.build())
println(URLBuilder(baseUrl).apply { path(users) }.build())
j

Jim

10/12/2021, 4:33 PM
ah nice, so I’ll just have a handful of builders around, one per version perhaps? thanks, I’ll look into this more
a

Aleksei Tirman [JB]

10/13/2021, 8:22 AM
Maybe, do whatever more convenient for you.
2 Views