Can I set base path to ktor client?
See original GitHub issueWhat I expect:
val http = HttpClient(Apache.create()) {
install(HttpBasePath) {
basePath = "http://somewhere.in"
}
}
http.get("/a") // => http://somewhere.in/a
http.get("http://a.b.com") // => http://a.b.com
I tried implementing the above feature, but I couldn’t tell a “localhost” string is the something set or just default.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:33
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Default request - Ktor
DefaultRequest allows you to configure a base part of the URL that is merged ... You can find the full example here: client-default-request....
Read more >Can't set a base url that includes path data : KTOR-730
Can 't set a base url that includes path data ; KTOR-697 The DefaultRequest feature overwrites any user specific data. 1 ; KTOR-759...
Read more >Change Retrofit Base URL on Runtime. | by Narayan Panthi
In this article we will implement a short & simple technique to change retrofit base url. Retrofit is a type-safe HTTP client for...
Read more >Is there a way to define a base URL in HttpClient By base UR
Is there a way to define a base URL in HttpClient By base URL I mean that all ... feature: https://ktor.io/clients/http-client/features/default-request.html.
Read more >kTor Android Client Tutorial - Performing Simple GET Request
Tired using Retrofit? Let's try kTor Android Client. In this kTor Android Client Tutorial we will learn performing a simple HTTP GET request ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
defaultRequest
can be used to get this behavior, sort of:Note that the
url
that is in scope in thedefaultRequest
block is the url defined in the original request–in this case theclient.get { }
call.It would be a very useful feature because most of REST APIs is some host + base path (usually with API version), so you want to extract this part and use for all your reqests that use particular instance of HttpClient Probably make sense to support new property
baseUrl/basePath
that includes protocol, host and path prefix. IMO it’s the most common way to specify base path. One more open question how to override base path (not base host), maybe we should use the same behavior as Retrofit, which ahas baseUrl (host + basePath). if particular request path starts from/
basePath will be ignored (request explicitly uses full path), otherwise basePath will be used