Send to API via POST Request in Delphi 10.3

Asked

Viewed 87 times

0

Good evening Guys, I’m a beginner in Delphi and I’m trying to send a creation request for an Api but I’m having some difficulty with the POST. How do I send this? I’m trying for this API: https://reqres.in Thanks for your help.

procedure TfrmPrincipal.Button7Click(Sender: TObject);
var
    res: TJSONValue;
    ParamNome: TRequestParam;
    ParamProfissao: TRequestParam;
    ParamArray: array of TRequestParam;
    ParamObj: TRequestParam;

begin

    ParamNome := RequestParam('name', 'Morpheus');
    ParamProfissao := RequestParam('job', 'Leader');
    ParamArray :=[
            ParamNome,
            ParamProfissao
            ];
    ParamObj := RequestParam('nome', ParamArray);

    res := TRestService.Ocorrencia.request(
        'https://reqres.in/api',
        'users',
       TRestService.POST


    );
    ParamObj := RequestParam('nome', ParamArray);
    Memo1.Lines.Text := ParamObj.valor.ToJSON;

end;
  • Anyone can help??

  • What’s happening with that code?

  • Thanks for the help I wasn’t able to copy, but I was able to pass the Paramobj value inside the Array. TRestService.POST, [ ParamObj ]

1 answer

0


I was able to solve by passing the Paramobj value inside the array.

var
    res: TJSONValue;
    ParamNome: TRequestParam;
    ParamProfissao: TRequestParam;
    ParamArray: array of TRequestParam;
    ParamObj: TRequestParam;

begin

    ParamNome := RequestParam('name', 'Felipe');
    ParamProfissao := RequestParam('job', 'Cozinheiro');
    ParamArray :=[
            ParamNome,
            ParamProfissao
            ];
    ParamObj := RequestParam('usuario', ParamArray);

    res := TRestService.Ocorrencia.request(
            'https://reqres.in/api',
            'users',
            TRestService.POST,
            [
                ParamObj
            ]
    );

    Memo1.Lines.Text := res.ToJSON;
   
end;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.