EUnsupportedActionParamType when using TArray<T> in Get request

Hi,

I try to use TArray< T > as input parameter for a get request. Is that supported? And if not, how could this be solved without individual requests per element?

The server throws the following error when starting:
Projext XXX.exe raised exception class EUnsupportedActionParamType with the message 'Cannot define action "test": Invalid type "TArray<System.Integer>" for param "test"

I tried TArray< T > and array of T. The last runs, but does only convert one of the parameters in an array.

The interface:

unit UnLMS_Service_Ritten_INT;

interface

uses
  XData.Service.Common,
  system.Generics.Collections,
  System.JSON;

type
  [ServiceContract]
  [Route('ritten')]
  IRittenService = interface(IInvokable)
    ['{6C57E613-CCAA-4883-AE82-915F6CB705C2}']

    [HttpGet] function test(test: TArray<integer>): integer;
  end;

implementation

initialization
  RegisterServiceType(TypeInfo(IRittenService));

end.

The function in the implementation:

function TRittenService.test(test: TArray<integer>): integer;
begin
 result := 1;
end;

The call with postman (java - Send an Array with an HTTP Get - Stack Overflow):
http://192.168.1.1:9997/app/ritten/test?test[]=1&test[]=3

It works when the request is defined as POST with the array in the body.

Unfortunately no, indeed arrays can only be received in JSON, not in URL.
In this case you will have to create a predefined number of parameters, like

    [HttpGet] function test(test1, test2, test3, test4: Integer): integer;

And maybe set all parameters optionals with a default value.

Hi Wagner,

Thank you. I'll create a work around.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.