Kong / Kong/unirest-ruby

Disable automatically added square brackets at end of array name

Open
#46 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
364
Forks
76
PR merge metrics
No merged PRs in 30d

Description

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](http://stackoverflow.com/questions/1688599/square-brackets-in-html-form-arrays-just-conventional-or-with-a-meaning), 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](http://nancyfx.org/)), 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 }
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the Unirest.post call and trace how the parameters hash serializes array values for the request body. Confirm the desired behavior with the examples in the issue: brackets should not be added automatically, while an explicitly named key such as "data[]" should remain usable.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.