elixir-plug / plug

Compose web applications with functions

Home Page:https://hex.pm/packages/plug

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add an encoding option for parameters with multiple values without the square brackets

Sed9yDataBank opened this issue · comments

Feature Request

I am using tesla + plug to POST some data to an image processing API.

I am using this to encode the URL

plug Tesla.Middleware.FormUrlencoded,
    encode: &Plug.Conn.Query.encode/1,
    decode: &Plug.Conn.Query.decode/1

This is what I am sending green=yes&blue=no&shades[]=300&shades[]=199

%{
    "shades" => [300, 199],
    "green" => "yes,
    "blue" => "no"
  }

Notice how I have the same parameter shades with two values 300 and 199

Unfortunately the image processing API returns 'shades' is missing

The parameter is shades not shades[] so I should be sending green=yes&blue=no&shades=300&shades=199 without the square brackets.

Along side to This

[?&, encode_pair(parent_field <> "[]", value, encoder)]
, Shouldn't there be an option to support the above use case?

I am not sure how frequent such encoding is, so my recommendation for now is to either encode it by hand or have your own version of the encoding functionality. :) Thank you!

Got it! thanks