By default params is applyed to body, as form param, not as query params. Is it possible to change POST request params behavior like in GET request?
Hi, @pltanton. Please, provide an example of your request.
If you use Fuel.get("http://myapi", listOf("foo" to "bar")) the GET request would be generated with empty body:
--> GET (http://myapi?foo=bar)
Body : (empty)
But if you use Fuel.post("http://myapi", listOf("foo" to "bar")) params would be injected as form body params, not as query params:
--> POST (http://myapi)
Body : foo=bar
Is it possible to use params as query params for POST request?
As I can see in sources, post method defined just like all other methods and didn't support to chose how to represent params in request.
As far as I understand params representation are chosed by Encoding::encoder method. What do you think about extending get, post, e.t.c methods by addotional parameter paramsEncoding of enum class ParamsEncodingMethod { FORM, MULTIPART_FORM, QUERY, JSON_IN_BODY, e.t.c } (or something like that)?
It is very useful to have possibility to chose that behaviour. Some REST APIs do not support parameters in POST request in form format, for example JIRA's API (at least if you trying to develop custom plugin). Futhermore it is also could be useful to pass params for get request in body.
Imo, the signature of Fuel.VERB method should be just the URL and parameters should be provided as a method. This way you could do Fuel.post(url).urlParams(...).bodyParams(...) (naming is bad, I know).
I think it should be considered a part of #225 .
Edit: The more I think about it, maybe for get request there should be a URLBuilder class or something. But it will make the library less intuitive.
As another data point, this limitation makes it impossible (or hard, at least) to use properly with the CouchDB API. Updating documents is a PUT operation that requires a rev query parameter. Actually...I think I can set an If-Match header instead, but the other query parameter options have no header alternative.
@mrenou, you can just pass your query params directly in url like Fuel.post('https://example.com?param=value&otherParam=otherValue')
Here is how your url can be encoded.
obviously, thank you @pltanton
@pltanton are you happy for this to be closed?
Sure
We'll close this one.
Found this post because was looking for the same functionality - how to append http query parameters to POST in Fuel. Ended up writing my own very small library that simplifies working with URL and HTTP parameters in Kotlin. While it is not Fuel-specific, but if anybody is interested, it has a small example with Fuel in README:
Most helpful comment
Imo, the signature of
Fuel.VERBmethod should be just the URL and parameters should be provided as a method. This way you could doFuel.post(url).urlParams(...).bodyParams(...)(naming is bad, I know).I think it should be considered a part of #225 .
Edit: The more I think about it, maybe for get request there should be a
URLBuilderclass or something. But it will make the library less intuitive.