I'm trying to build a network module for Multiplatform project with ktor.
My code for GET request is something like this:
val result = httpClient.get<HttpResponse> {
url {
protocol = baseProtocol
host = baseUrl
encodedPath = urlPath
}
}
In some point my path contain a user id like this /users/{user_id}.
I can do a search and replace in string and replace this user_id with actual value, BUT is there any other way to do this? any ktor specific way.
For example with Retrofit we have this:
@GET("users/{user_id}/")
SomeData getUserData(@Path("user_id") String userId);
EDIT: adding more code
val result = httpClient.get<HttpResponse> {
url {
protocol = baseProtocol
host = baseUrl
var requestPath = request.requestPath.value
request.path?.forEach {
requestPath = requestPath.replace(it.first, it.second)
}
encodedPath = requestPath
if (request.parameters != null) {
parameters.appendAll(getParametersFromList(request.parameters))
}
}
the request.path?.forEach { requestPath = requestPath.replace(it.first, it.second)} replacing any runtime path value.