d34dman / drupal-jsonapi-params

A package to manage json-api params
ISC License
59 stars 8 forks source link

Allow extra query string params to be added. #23

Closed patrickcate closed 3 years ago

patrickcate commented 3 years ago

It would be great if there was a method that allowed for extra arbitrary query strings to be added to the query. The https://www.drupal.org/project/jsonapi_include module requires jsonapi_include=1 be added to the url for instance.

Something like:

apiParams
  // Add Extra query string.
  .addExtra('jsonapi_include', 1)

would easily enable support for this.

d34dman commented 3 years ago

Thanks for the suggestion @patrickcate , we now have addCustomParam method in release 1.2.0.

apiParams
  // To add `foo=bar` to the query.
  .addCustomParam({foo: 'bar'})
  // To add `foo[bar]=baz` to the query.
  .addCustomParam({ foo: {bar: 'baz'}})
  // To add `bar[0]=a&bar[1]=b&bar[2]=c` to the query.
  .addCustomParam({ bar: ['a', 'b', 'c']})