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

How to describe urls with ordered indexed array? #423

Open
denisvmedia opened this issue Mar 10, 2018 · 0 comments
Open

How to describe urls with ordered indexed array? #423

denisvmedia opened this issue Mar 10, 2018 · 0 comments

Comments

@denisvmedia
Copy link

Here is an example url (I tried to describe it with with both OpenAPI and API BluePrint but failed):

http://example.com/api/items?filter[0][field]=value1&filter[0][type]=gte&filter[0][x]=490&filter[1][field]=value2&filter[1][type]=lte&filter[1][x]=200&filter[2][field]=value3&filter[2][type]=between&filter[2][x]=100&filter[2][y]=300

Some additional notes: we have an array of filters that should accept some values. The parameters can be represented in JSON like this:

[
  {
    "field": "value1",
    "type": "gte",
    "x": 490
  },
  {
    "field": "value2",
    "type": "lte",
    "x": 200
  },
  {
    "field": "value3",
    "type": "between",
    "x": 100,
    "y": 300
  }
]

With this type of query parameters indexing we get natural arrays in PHP without any additional "movements" using something like this:

parse_str('filter[0][field]=value1&filter[0][type]=gte&filter[0][x]=490&filter[1][field]=value2&filter[1][type]=lte&filter[1][x]=200&filter[2][field]=value3&filter[2][type]=between&filter[2][x]=100&filter[2][y]=300', $result);
var_dump($result);
/** output:
array(1) {
  ["filter"]=>
  array(3) {
    [0]=>
    array(3) {
      ["field"]=>
      string(6) "value1"
      ["type"]=>
      string(3) "gte"
      ["x"]=>
      string(3) "490"
    }
    [1]=>
    array(3) {
      ["field"]=>
      string(6) "value2"
      ["type"]=>
      string(3) "lte"
      ["x"]=>
      string(3) "200"
    }
    [2]=>
    array(4) {
      ["field"]=>
      string(6) "value3"
      ["type"]=>
      string(7) "between"
      ["x"]=>
      string(3) "100"
      ["y"]=>
      string(3) "300"
    }
  }
}
**/

So, this is not something exotic, this is a normal php-style query uri.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant