fabriciocolombo / delphi-rest-client-api

A Delphi REST client API to consume REST services written in any programming language.
Apache License 2.0
380 stars 182 forks source link

Passing Array Type #54

Closed Timothyoverton closed 8 years ago

Timothyoverton commented 8 years ago

Hi Guys,

I have this working with a single object but when I add in array of objects, I get nothing back.

This was working: type TLoginResponse = class public id: string; end; var loginResponse: TLoginResponse; begin loginResponse := FabRestClient.Resource('https://blah//ro') .Accept(RestUtils.MediaType_Json) .contentType(RestUtils.MediaType_Json) .Post(body);

This isn't, although the call is returning 200 and there is a result in Fiddler: type TAccountArray = TArray; var test: TAccountArray; begin test := DelphiRestClient.Resource(baseApi + url) .Header('Authorization', 'Bearer ' + bearerToken) .Accept(RestUtils.MediaType_Json) .Get();

In the IDE hovering over Get its only giving me the string parameter, so I've added in the USE_GENERICS directive to the compiler. It won't allow me to add TArray as the Get parameter, it says type mismatch. Any thoughts?

thomaserlang commented 8 years ago

You need to specify what it has to return it as.

Try:

Get<TheTYPE>()

Check the examples in the readme file.

Timothyoverton commented 8 years ago

Thanks Thomas,

I was able to get it working with TList. However, TArray would not pass the returned data. Also I ended up using TObjectList however, when this is passed back by the RestClient, OwnsObjects of TObjectList is set to false. I've been able to get around this by creating my own descendant which forces OwnObjects to true, so that you can call Free and the TAccounts are free'd as well. eg. TBfObjectList = class(TObjectList) published constructor Create; end;

constructor TBfObjectList.Create; begin Inherited Create; FOwnsObjects := true; end;

Is TArray<> not supported? (I'm using XE6.)

Timothyoverton commented 8 years ago

I will use TList or my own TObjectList - thanks.