RTC Forums
April 28, 2024, 10:21:59 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: REST question  (Read 3545 times)
Andrew.W
RTC License
***
Posts: 43


« on: June 13, 2017, 10:42:45 AM »

Hi Daniel

I'm trying to setup a simple REST client using RTC.

I'm using one of the test functions here.

http://www.jsontest.com/

and specifically this function

http://ip.jsontest.com/

Can I check with you:

- Are the right client components TRtcHttpClient and TRtcClientModule?
- What should the value of DataFormat be?

Thanks
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: June 13, 2017, 11:10:53 AM »

Expecting the name of the function as part of the sub-domain and making everything accessible from the root URI is the WORST possible use of HTTP - EVER. Also, as far as I can tell, most tests on that page do NOT require any parameters in JSON format, which makes me wonder how that page qualifies as a "JSON test".

Anyway ... this piece of code should do what you wanted ...

  var
    Res:TRtcValue;
  begin
  RtcHttpClient1.ServerAddr:='ip.jsontest.com';
  RtcHttpClient1.ServerPort:='80';
  RtcHttpClient1.AutoConnect:=True;

  RtcClientModule1.Client:=RtcHttpClient1;
  RtcClientModule1.DataReqMode:=req_queryNameText;
  RtcClientModule1.DataFormat:=fmt_JSON;

  RtcClientModule1.Prepare('');
  Res:=RtcClientModule1.Execute(False);
  try
    if Res.isType=rtc_Record then
      Label1.Caption:='IP = '+Res.asRecord.asText['ip'];
  finally
    Res.Free;
    end;
  end;


Best Regards,
Danijel Tkalcec
Logged
Andrew.W
RTC License
***
Posts: 43


« Reply #2 on: June 13, 2017, 05:32:15 PM »

Thanks Daniel
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.023 seconds with 16 queries.