fabriciocolombo / delphi-rest-client-api

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

Post Single object and get array object #123

Open devzonetrack opened 6 years ago

devzonetrack commented 6 years ago

Howto post single object as parameter and get array object as result?

fernand-o commented 6 years ago

something like this should work:

type
  TUser = class
    name: string;
    username: string;
  end;
  TUsers = TArray<TUser>;

  TParams = class
    kind: string;
  end;
var
  Params: TParams;
  Users: TUsers;
begin
  Params := TParams.Create;
  Params.kind := 'admin';

  Users := Client.Resource('https://jsonplaceholder.typicode.com/users').Get<TUsers>;
  // or 
  Users := Client.Resource('https://jsonplaceholder.typicode.com/users').Post<TUsers>(Params);
end;
devzonetrack commented 6 years ago

Helo fernand-o Thank very much this working fine.