Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
KTor URLBuilder encodedPath with dynamic path

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.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!