Recent

Author Topic: Is it practical or even possible to generate a REST API for the LCL controls?  (Read 1553 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1165
    • HowTos Considered Harmful?
Is it practical or even possible to generate a REST API for the LCL controls?

Can it be generated automatically from its published properties?

I just saw this announcement New Swagger/OpenAPI Client Generator for FPC  by @abouchez.

Forgive me if my question sounds stupid, but REST APIs have never been a thing for me. I've never truly worked with them.
« Last Edit: September 16, 2024, 09:26:08 am by vfclists »
Lazarus 3.0/FPC 3.2.2

nummer8

  • Full Member
  • ***
  • Posts: 124
I don't know if I understand your question correctly but check the following package
lazarus->components->sqldbrest-> lazsqldbrest.lpk
It is a package to assist you visually in creating REST endpoints direct from data.


Thaddy

  • Hero Member
  • *****
  • Posts: 19275
  • Glad to be alive.
Yes, that is possible.
A good example are the Google API' s that are machine generated and fully rest.
The package also contains the code that does the actual generation.
You could adapt it to an LCL api generator since components can already be represented in JSON,
objects are fine constructs. You can even initialize them with constructors.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Hello,
here is an example using SQLDBRestBridge
In attachment a zip file with two projects and a sqlite3 database
to compile the projects you must install  lazsqldbrest and weblaz packages. To use the sqlite3 database you must have the sqlite client library installed.
The first project restreadonly launch a rest api server on port 3000. This server is connected to the sqlite3 database .  The connection to the database is here in the code :
Code: Pascal  [Select][+][-]
  1. begin
  2.     // Or set in code.
  3.    // C.ConnectionType:=TPQConnectionDef.TypeName;
  4.    // C.DatabaseName:='fpctest';
  5.    // C.HostName:='localhost';
  6.    // C.UserName:='user';
  7.    // C.Password:='secret';
  8.    C.ConnectionType:=TSQLite3ConnectionDef.TypeName;
  9.    C.DatabaseName:='selzig.db3';
  10.    // C.HostName:='localhost';
  11.    // C.UserName:='user';
  12.    // C.Password:='secret';
  13.     end;
The second project jsonclient  is used  to connect to  the rest Api server and get data in json format.
the two projects come from fpcsource and lazarus.

Friendly, J.P
« Last Edit: August 30, 2025, 10:25:14 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

 

TinyPortal © 2005-2018