TRESTClient availability in FPC/Lazarus lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- kveroneau · 2016-03-30 18:40 I noticed that Delphi has this pretty awesome REST library:  http://do cwiki.embarcadero.com/RADStudio/Seattle/en/REST_Client_Library Has anybody tries to use this in a Lazarus project, or has it been ported over to Lazarus yet?  Is there an alternative REST client library available? ---------------------------------------------------------------------- DonAlfredo · 2016-03-30 18:45 Try the mORMot ! www.synopse.info ---------------------------------------------------------------------- kveroneau · 2016-03-30 19:49 mORMot appears to be more of a client-server framework, which seems more like a web framework.  TRestClient is strictly a client-side REST API client, so that we can talk to remote REST services such as Twitter, Facebook, among others from our application.  Basically, my end goal is to be-able to talk with the Twilio REST API:  https://www.twilio.com/docs/api/rest I'd like to be able to say, connect to their REST API from my Lazarus desktop application to display call logs, SMS messages, and grab other stats from my Twilio account.  TRestClient appears to be the perfect tool for this job, but I am unsure if it's available in Lazarus or not. ---------------------------------------------------------------------- JD · 2016-03-30 21:40 Brook Framework has REST capabilities http://silvioprog.github.io/brookframework/ JD ---------------------------------------------------------------------- ttomas · 2016-03-30 22:20 You can try delphi-rest-client-api Original project https://github.com/fabriciocolombo/delphi-rest-client-api Lazarus fork https://github.com/esvignolo/delphi-rest-client-api ---------------------------------------------------------------------- Jurassic Pork · 2016-03-31 04:46 hello, you can use also RestRequest unit from here"]>Blockedwhich uses  indy components.  Success on Windows 7 Lazarus 1.6   : 1 - Install Indy ( see [url=http://wiki.freepascal.org/Indy_with_Lazarus]lazarus wiki page[/b][/u][/color]) 2 - Use my modified version of RestRequest.pas in attachment application console project to read data from a fake rest server (for testing). May be need to change the path to Indy files.  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; {$MODE Delphi}uses  SysUtils,  Classes,  RestRequest in 'RestRequest.pas'; var RestReq: TRestRequest;    RestResp: THttpResponse;begin  try    RestReq := nil;    try   //   RestReq := T RestRequest.Create().Domain('jsonplaceholder.typicode.com').Path('todo s').Path('1');           RestReq := TRestRequest.Create().Domain('json placeholder.typicode.com').Path('posts');      RestResp := RestReq.Get();      if RestResp.ResponseCode = 200 then WriteLn('Your todo was added!') else WriteLn('Failed to add your todo.');      WriteLn(RestResp.ResponseStr);      Readln;    finally      RestReq.Free;    end;  except    on E: Exception do      Writeln(E.ClassName, ': ', E.Message);  end;end.  May be someone has time  to replace indy components with fcl or synapse components ( if possible)    Friendly, J.P ---------------------------------------------------------------------- Leledumbo · 2016-03-31 06:05 Most REST implementation is just plain HTTP with JSON response (well, some requires authentication/authorization using certain protocols but that's also on top of plain HTTP). fphttpclient + fpjson unit should already cover the needs. ---------------------------------------------------------------------- kveroneau · 2016-03-31 17:11 Thank you for the helpful replies here.  I am looking to be as cross- plat compatible as possible, and my dev box is actually a Debian box, so components which strictly depend on Windows libraries are a no-go.  The delphi-rest-client-api appears to depend on WinHTTP, and WinINET, or perhaps the README.md file wasn't updated after the Lazarus fork... I will first give the RestRequest unit a shot, the one provided by Jurassic Pork, although I'd wish for as little external deps as possible, I'll check it out and see how it works. In the end, I may end up rolling my own class using Leledumbo's suggestion of using fphttpclient+fpjson units, as this would make it more cross-plat, and would be more de-coupled from LCL components, so it has the benefit of working with both pure FPC(non-Lazarus) programs, and also working with Lazarus as well.  I am also thinking of taking a look at the INet library, as I believe they also have a HTTPClient class which may work to communicate with REST as well. As Leledumbo mentions, the only issue I may run into with rolling my own REST API client is dealing with authentication, but most endpoints just use a simple header, so that shouldn't be a big deal. ---------------------------------------------------------------------- Leledumbo · 2016-03-31 18:06 Take a look on how I implement one for Instagram: https://bitbucket.org/leledumbo/instapas fpctwit (https://bitbucket.org/reiniero/fpctwit) also has Twitter and Plurk implementation, which uses OAuth v1.0a protocol. ---------------------------------------------------------------------- ttomas · 2016-03-31 20:51 Quote from: kveroneau on March 31, 2016, 07:11:31 pmThe delphi-rest- client-api appears to depend on WinHTTP, and WinINET, or perhaps the README.md file wasn't updated after the Lazarus fork... Old readme.md You can look at files HttpConnectionXXX.pas delphi-rest-cient-api have interface implementation for FpHTTP and Indy (cross platform) and WinHTTP, WinINET (windows only). ---------------------------------------------------------------------- Jurassic Pork · 2016-03-31 23:00 hello, here is an example (for post) to dump json data returned from a REST server using free pascal libraries : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // uses fphttpclient, fpjson, jsonparser; Procedure TForm1.DumpJSONData(J : TJSonData; DOEOLN : Boolean = True); Var  I : Integer;  DataString : String; begin  // JSONType property determines kind of value.  Case J.jsontype of    jtNull   : Memo1.Append('Null');    jtBoolean : If J.AsBoolean then                  Memo1.Append('True')                else                  Memo1.Append('False');    jtNumber : {JSONNumber has extra NumberType property                which determines kind of value (int/float).}               Case TJSONNumber(J).NumberType of               ntInteger : Memo1.Append(inttostr(J.AsInteger));               ntFloat   : Memo1.Append(floattostr(J.AsFloat));               end;    jtString : Memo1.Append('"' + J.AsString +'"');    jtArray  : begin               Memo1.Append('======================');             For I:=0 to J.Count-1 do                 begin                 DumpJSONData(J.Items[I],False);                 If I