TMS XData: A Powerful Framework for Delphi REST/JSON Servers
If you are looking for a way to create HTTP/HTTPS servers that expose your Delphi objects through REST/JSON, you might want to check out TMS XData. TMS XData is a full-featured Delphi framework that allows you to create multi-tier applications with ease and flexibility.
TMS XData v4.6.0.1 Delphi XE2- Delphi 10.3.2 Rio Full Source
Download File: https://www.google.com/url?q=https%3A%2F%2Fcinurl.com%2F2vNAjg&sa=D&sntz=1&usg=AOvVaw3IW5RL27bep4jSm1cQeP9t
TMS XData is based on the standard OData protocol, which means that your server can be easily accessed from different client platforms like .NET, Java, jаvascript, and more. You can use standard HTTP methods like POST, GET, PUT, DELETE, and PATCH to perform data request and data modification operations on your server resources.
TMS XData also supports streams (blobs), partial update of objects, service operations for custom business logic, and a powerful query mechanism that lets you filter, sort, paginate, and expand your data. You can use any database supported by TMS Aurelius as your back end, such as SQL Server, MySQL, PostgreSQL, Oracle, Firebird, etc.
TMS XData is built on top of TMS Sparkle, which provides a robust HTTP/HTTPS server architecture based on Windows http.sys stack. This means that your server can benefit from features like kernel-mode caching, kernel-mode request queuing, SSL support in kernel-mode, and port sharing among multiple applications.
If you want to learn more about TMS XData and how it can help you create powerful Delphi REST/JSON servers, you can visit the official website[^1^] or download the latest version[^2^]. You can also find some useful tutorials[^3^] and demos[^4^] on how to use TMS XData in your projects.
In this article, we will show you how to create a simple TMS XData server that exposes a list of products and categories from a SQLite database. We will also show you how to use TMS Web Core to create a web client that consumes the data from the server.
To get started, you will need to install TMS XData and TMS Web Core on your Delphi IDE. You can download them from the links provided in the previous section. You will also need to download the sample database file and copy it to your project folder.
First, we will create the TMS XData server project. Open Delphi and create a new VCL Forms Application. Save the project as XDataServer.dproj and the main form as MainForm.pas. On the main form, drop a TSparkleHttpSysDispatcher component and set its Port property to 2001. This component will handle the HTTP requests from the clients.
Next, we will define the entities that represent our data model. Right-click on the project and select Add New | Other | Aurelius Entity. Save the unit as ProductEntity.pas and add the following code:
unit ProductEntity;
interface
uses
Aurelius.Mapping.Attributes;
type
[Entity]
[Table('Products')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
TProduct = class
private
[Column('Id', [TColumnProp.Required])]
FId: Integer;
[Column('Name', [TColumnProp.Required], 100)]
FName: string;
[Column('Price', [])]
FPrice: Double;
[Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])]
[JoinColumn('CategoryId', [TColumnProp.Required], 'Id')]
FCategory: Proxy<TCategory>;
public
property Id: Integer read FId write FId;
property Name: string read FName write FName;
property Price: Double read FPrice write FPrice;
property Category: Proxy<TCategory> read FCategory write FCategory;
end;
[Entity]
[Table('Categories')]
[Id('FId', TIdGenerator.IdentityOrSequence)]
TCategory = class
private
[Column('Id', [TColumnProp.Required])]
FId: Integer;
[Column('Name', [TColumnProp.Required], 100)]
FName: string;
public
property Id: Integer read FId write FId;
property Name: string read FName write FName;
end;
implementation
end.
This code defines two classes, TProduct and TCategory, that are mapped to the Products and Categories tables in the database. The TProduct class has a property called Category that is a proxy for the TCategory class. This means that the category of a product is lazily loaded when needed.
Now we will create the XData server module that will expose our entities through REST/JSON. Right-click on the project and select Add New | Other | XData Server Module. Save the unit as XDataServerModule.pas and add the following code:
unit XDataServerModule;
interface
uses
System.SysUtils, System.Classes,
XData.Server.Module,
XData.Comp.Server,
Aurelius.Engine.ObjectManager,
Aurelius.Drivers.Interfaces,
Aurelius.Drivers.SQLite,
Aurelius.Schema.SQLite,
Aurelius.Comp.Connection;
type
[XDataModule('$model')]
TXDataServerModule1 = class(TXDataServerModule)
Connection: TAureliusConnection;
procedure DataModuleCreate(Sender: TObject);
procedure DataModuleDestroy(Sender: TObject);
private
Private declarations
FManager: TObjectManager;
function CreateConnection: IDBConnection;
public
Public declarations
function GetManager: TObjectManager;
end;
var
XDataServerModule1: TXDataServerModule1;
implementation
%CLASSGROUP 'Vcl.Controls.TControl'
$R *.dfm
procedure TXDataServerModule1.DataModuleCreate(Sender: TObject);
begin
Connection.Connected := True;
end;
procedure TXDataServerModule1.DataModuleDestroy(Sender: TObject);
begin
Connection.Connected := False;
end;
function TXDataServerModule1.CreateConnection: IDBConnection;
begin
Result := TSQLiteNativeConnectionAdapter.Create(
ExtractFilePath(ParamStr(0
e033bf56a8