TRestClient and Array Parameters in a Get

TRestClient and Array Parameters in a Get

I got blocked using TRestClient with a REST Service that requires string arrays in a Get.

https://stackoverflow.com/questions/24059773/correct-way-to-pass-multiple-values-for-same-parameter-name-in-get-request

does describe the problem in all the details. I cannot influence the server code implementation and have to find a solution now. The current implementation by the server is done by an URL &id=1&i2=1&id=3 and the syntax id=[1;2;3] is not supported. Today the Delphi implementation of TRESTRequestParameter does only allow unique parameter names which is actually not that bad.

Perhaps somebody has already solved this problem? If not then I thought to extend TRESTRequestParameterOptions with a value poFlattenArrayContent. This would allow to patch TCustomRESTRequest.DoPrepareQueryString to a logic of flatten id=[1;2;3]- > &id=1&i2=1&id=3

I ask this issue here because others could benefit perhaps as well. And if I have a running solution I would suggest it as a fix to the TRestClient within http://quality.embarcadero.com (I know they will call it enhancement request).

regards Günther

Comments

  1. Marco Cantù I thought first as well. But that would potentially break existing code (AddItem does check for existence of the "name" and overwrite the value if already exists). As well take case on the representation
    poArrayFlat -> &id=1&id=2 or
    poArrayPHP &id[]=1&id[]=2
    could be real world use cases.

    ReplyDelete
  2. I ran into this issue as well.. Luckily I was able to get the backend server team to change the API on their server to suit my needs.. Otherwise I would have had to resort to building the URLs manually, but having support for this in TRestClient would be great..

    ReplyDelete
  3. Brian Ford RSP-20398 is already set to "open". I hope we get that feature added to the next version.

    ReplyDelete

Post a Comment