Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compat] original httpbin returns either lists or scalars depending on input data #37

Closed
Tracked by #91
splitbrain opened this issue Aug 11, 2020 · 6 comments
Closed
Tracked by #91
Labels
compat Tracking issues around compatibility with original httpbin implementation

Comments

@splitbrain
Copy link

The answers between httpbin and httpbingo differ. httpbingo will always return an array for each parameter or header, while httpbin will return simple objects and use sub arrays only when needed. I think your behaviour is maybe a more sensible approach, but it's harder to read for humans and makes it hard to use httpbingo as a drop-in replacement for httpbin.

curl -s  'http://httpbin.org/get?foo=bar&foo=baz&what=this' |jq
{
  "args": {
    "foo": [
      "bar",
      "baz"
    ],
    "what": "this"
  },
...
$ curl -s  'http://httpbingo.org/get?foo=bar&foo=baz&what=this' |jq 
{
  "args": {
    "foo": [
      "bar",
      "baz"
    ],
    "what": [
      "this"
    ]
  },
...
@splitbrain
Copy link
Author

I just noticed that this is somewhat a duplicate of #15 but not quite.

@mccutchen
Copy link
Owner

Yeah, I'm really torn on this. While making httpbingo.org a drop-in replacement for (at least the most common/basic functionality of) httpbin.org would be great, that particular pattern is particularly ugly to implement in Go. Maybe I'll take another pass at this and see how bad it really is.

@waitingsong
Copy link

waitingsong commented Jan 30, 2021

I think common behaviour is:

GET  /get?foo=12&bar=23

Should got

{ 
 foo: "12",
 bar: "23",
}

and then

GET  /get?foo[]=12&foo[]=23

Should got

{ 
 foo: ["12", "23"],
}

@mccutchen
Copy link
Owner

and then

GET  /get?foo[]=12&foo[]=23

Should got

{ 
 foo: ["12", "23"],
}

Minor note: There is no special handling of ?foo[]=12&foo[]=23 style of query param in either go-httpbin or the original httpbin. That request will result in a response like

{
    "foo[]": ["12", "23"]
}

in both projects. Here's original httpbin:

$ curl -s 'https://httpbin.org/get?foo[]=1&foo[]=2' | jq .args
{
  "foo[]": [
    "1",
    "2"
  ]
}

and go-httbin:

$ curl -s 'https://httpbingo.org/get?foo[]=1&foo[]=2' | jq .args
{
  "foo[]": [
    "1",
    "2"
  ]
}

Note that the name of the argument is foo[], not foo.

@bbx-winner
Copy link

@mccutchen Hi, here's my solution to this issue: #73, wish for your comment.

@mccutchen mccutchen changed the title differences in answer format to httpbin [compat] original httpbin returns either lists or scalars depending on input data Nov 10, 2022
@mccutchen mccutchen added the compat Tracking issues around compatibility with original httpbin implementation label Nov 11, 2022
@mccutchen
Copy link
Owner

I've taken a pass at this and #15 from time to time over the last couple of years, but I'm never satisfied with the complexity that it requires.

Ultimately, I don't think this (admittedly large) part of backwards-compatibility is worth pursuing, and prefer the consistency of our existing approach: any key-value pair where each key may correspond to one or more values will always be represented as a JSON array (AKA list, slice, etc) with one or more items.

I will gladly take a look at future pull requests if someone does come along with an implementation that somehow

@mccutchen mccutchen closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compat Tracking issues around compatibility with original httpbin implementation
Projects
None yet
Development

No branches or pull requests

4 participants