question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make use of x-form-urlenoded parameters more explicit

See original GitHub issue

Make use of x-form-urlenoded parameters more explicit

Description

If have to send requests to an API that I do not control, where some parameters are sent inside the URL and others are sent as x-form-urlencoded body. I don’t see an easy way to do this with fuel. In my opinion this is caused by the rather implicit handling of parameters.

Proposed Solution

Add a new function urlEncodedBody that sets a body explicitly with the correct headers, like jsobBody.

Example:

FuelManager.post("path/", listOf("param" to 1))
    .urlencodedBody(listOf("foo" to "foo", "bar" to "bar"))

would set the Header Content-Type : application/x-www-form-urlencoded and set a body `Body: “foo=foo&bar=bar”.

Additional change

Remove automatic encoding in the x-form-urlencoded body. In my opinion, this is bad design anyway. The parameters argument should not be used for two independent features. To a developer, those three lines look very similar, yet the parameters behave “arbitrarily”.

FuelManager.get("path/", listOf("param" to 1))
FuelManager.post("path/", listOf("param" to 1))
FuelManager.post("path/", listOf("param" to 1))
    .jsonBody("{}")

Additional context

I find it hard to understand when Fuel puts parameters in the URL or encode them as x-form-urlencoded body in general. I have used Fuel for almost a year know on a daily basis and always have difficulties to remember how those parameters are encoded in POST request.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
adiykehlercommented, Dec 3, 2019

Thanks for your quick reply.

That “arbitrary” behaviour is also how your browser works. I like the addition of the urlencodedbody, but the current behaviour is not bad design.

It feels arbitrary to me, because I’m not familiar with browsers or Javascript. If this is common style in HTTP libraries, then ignore my additional change request. I’m OK with that.

0reactions
kittinunfcommented, Dec 7, 2019

I think it is a good addition to the library, though I don’t think the current design is that bad, however, we tried to cover the common use-cases.

So there might be some cases that we don’t support! All in all, I am up for this change though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling URL Encoded Form Data in Spring REST
Learn how to handle URL encoded form data in Spring REST. ... which can take two values, namely application/x-www-form-urlencoded and ...
Read more >
Character Encoding for Parameters in application/x-www- ...
I wonder how hard it can be to add a charset encoding parameter to the browser's request and make it mandatory to specify...
Read more >
Retrofit — Send Data Form-Urlencoded - Future Studio
Use form -urlencoded requests to send data to a server or API. The data is sent within the request body and not as...
Read more >
Encoding data for POST requests
URLSearchParams handles encoding and decoding application/x-www-form-urlencoded data. It's pretty handy, because, well…
Read more >
Understanding HTML Form Encoding: URL Encoded and ...
application /x-www-form-urlencoded - Represents a URL encoded form. This is the default value if enctype attribute is not set to anything.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found