Closed violabs closed 11 months ago
You could easily solve this with your own extension function:
fun Request.requestParams(vararg params: Pair<Any, Any>) =
copy(url = "${url}?${params.joinToString("&") { "${it.first}=${it.second}" }}")
@Inkemann Nice proposal, but it needs enhancements in order to become compliant to http: You need to encode the parameters to apply appropriate url parameter formating.
The overall idea is nice, but we have to carefully decide, where we draw the line between a dedicated http lib and the convenient wrappers we offer in fritz2. So not sure yet, whether we should and will offer this as built-in.
@chausknecht Unlike the built-in append
function this also requires particular awareness if one doesn't want to create a completely broken url as it always has to be called last in a chain of url-building functions. There would have to be major changes to the api to allow for adding url parameters one at a time or comparable complex logic.
My quick and admittedly very dirty solution could be useful for the specific request made here, but it's not very versatile.
I would suggest having a look at the ktor http client. It comes with lots of features, runs on JS and Java and is quite mature. So for more than real basic use cases, I would always prefer some dedicated solution.
@violabs Does this proposal helps you? Can we close this issue?
Yeah. That should be fine. Maybe a mention in the docs would help not have this brought up again. Thanks!
This feature is now implemented by PR #790 in https://github.com/jwstegemann/fritz2/releases/tag/v1.0-RC12
It would be nice to have a convenient way to use request params like:
and have it construct:
api/endpoint?limited=true&option=Hello
I understand you can just create the http function with that string, but it would be nice to be able to reuse the base url without calling it every time.