Closed chameleon82 closed 4 years ago
you can do sth like this: def myRequest(base: Uri) = basicRequest.get(uri"$base/x/y/z")
. The initial token, if it's scheme+host is treated differently and not escaped: https://sttp.readthedocs.io/en/latest/model/uri.html#special-cases
Thanks, it gives me some ideas
trait UrlProvider {
def getNext: String
}
class RepositoryApi(urlProvider: UrlProvider) {
basicRequest
.method(Method.GET, uri"${urlProvider.getNext}/search/repositories?q=$query&sort=$sort")
}
The only concern is about a better way to handle passed urls for such a scenario like deprioritize url weights in round-robin wrapper.
I will close the issue as it able to make api abstract and simple enough
for load-balancing/round-robin you could have a backend wrapper (https://sttp.readthedocs.io/en/latest/backends/wrappers/custom.html) which substitutes the scheme/host/port in a request with the next target. So you would construct the request with .get(uri"http://loadbalance/x/y/z")
, and the http://loadbalance
part would be substituted with the next choice by the backend
Currently with
uri
i can specify only full URL to a resource likeWould be better to separate server part and path part into something like this?
The idea is to specify server before actual call, but after request model was specified. It will allow to manage server urls dynamically and create wrappers with specific logic like round-robin, but keep model definition declarative.
As an alternative servers or interface to implement my own url provider could be specified within
SttpBackend