Kong / unirest-ruby

Unirest in Ruby: Simplified, lightweight HTTP client library.
http://unirest.io/ruby
MIT License
364 stars 81 forks source link

Disable automatically added square brackets at end of array name #46

Open adm7373 opened 7 years ago

adm7373 commented 7 years ago

Say I want to post an array of data to a remote source:

    array = [1,2,3]
    Unirest.post "https://www.my-website.com", parameters: { data: array }

When I receive the HTTP request on my-website.com, the body of the POST looks like this: data[]=1&data[]=2&data[]=3

According to this StackOverflow post, those square brackets are a convention to "address a limitation of PHP, which doesn't generate an array automatically if multiple values with the same name are submitted". All well and good if I'm posting to a PHP server, but if I'm posting to a different kind of server (in my case NancyFx), I can't easily get that data into an array.

I think it would make sense to get rid of these brackets by default and allow developers using unirest-ruby to post to a PHP server to do something like this:

    array = [1,2,3]
    Unirest.post "https://www.my-website.com", parameters: { "data[]": array }