top of page

Unconventional Training Club

Public·13 members
Ľudovít Leško
Ľudovít Leško

TMS XData V4.6.0.1 Delphi XE2- Delphi 10.3.2 Rio Full Source




TMS XData v4.6.0.1 Delphi XE2- Delphi 10.3.2 Rio Full Source


TMS XData v4.6.0.1 Delphi XE2- Delphi 10.3.2 Rio Full Source




TMS XData is a Delphi framework that allows you to create HTTP/HTTPS servers that expose data through REST/JSON. It is based on the standard OData protocol and uses TMS Sparkle as its core communication library. TMS XData supports Delphi XE2 and up, and can be used on different platforms and operating systems. In this article, we will review some of the features and benefits of using TMS XData, and show how to install and use the latest version (v4.6.0.1) with Delphi XE2- Delphi 10.3.2 Rio.


DOWNLOAD: https://tweeat.com/2w45ab


Features and Benefits of TMS XData




TMS XData offers a high-level and smooth learning curve for creating REST/JSON servers in Delphi. You can use the concept of service operations to create server-side methods (business logic) that are mapped to endpoints in your API. Whenever an endpoint is requested, your method is executed, without having to worry about low-level mechanisms such as HTTP communication, HTTP methods, JSON handling, etc. You can also define authorization and authentication, multitenancy information, and Swagger documentation output for your API.


TMS XData is optionally integrated with TMS Aurelius ORM, which allows you to create automatic CRUD endpoints based on applications with existing Aurelius mappings. You can use regular Delphi types to declare your methods and tag them with attributes to properly bind the endpoints to them. For example, consider that you have an Aurelius class mapped as follows:


[Entity, Automapping] TCustomer = class strict private FId: integer; FName: string; FTitle: string; FBirthday: TDateTime; FCountry: TCountry; public property Id: Integer read FId write FId; property Name: string read FName write FName; property Title: string read FTitle write FTitle; property Birthday: TDateTime read FDateTime write FDateTime; property Country: TCountry read FCountry write FCountry; end;


With a few lines of code, you can create an XData server to expose these objects through REST/JSON. You can retrieve an existing TCustomer with an id equal to 3 using the following HTTP request, for example:


GET /tms/xdata/Customer(3) HTTP/1.1 Host: server:2001


And the JSON representation of the customer will be returned in the body of the HTTP response:


"$id": 1, "@xdata.type": "XData.Default.Customer", "Id": 3, "Name": "Maria Anders", "Title": "Sales Representative", "Birthday": "1980-05-20", "Country": null


You can perform changes to objects through the REST interface, using POST method to create new objects, DELETE to remove objects, and PUT or PATCH to update the objects. For example, the following request will change the value of the Title property of the customer resource specified in the previous example:


PATCH /tms/xdata/Customer(3) HTTP/1.1 Host: server:2001 "Title": "Marketing Manager"


TMS XData also provides a full-featured query mechanism that allows you to perform complex queries on existing objects using URL conventions inspired by OData. For example, you can retrieve customers with country name equal to "USA", ordered by customer's name, using the following request:


GET /tms/xdata/Customer?$filter=Country/Name eq 'USA'&$orderby=Name HTTP/1.1 Host: server:2001


TMS XData supports several databases in back end, such as SQL Server, MySQL, PostgreSQL, Oracle, Firebird, etc., through TMS Aurelius. It also supports streams (blobs), associations, proxies, and other features of TMS Aurelius.


TMS XData uses TMS Sparkle as its core communication library, which provides several advantages, such as:



  • HTTP/HTTPS server based on Windows http.sys stack



  • Support for HTTP Secure (HTTPS)



  • Kernel-mode caching and kernel-mode request queuing (less overhead in context switching)



  • Multiple applications/process can share (respond) the same port (at different addresses)



  • Secure Sockets Layer (SSL) support in kernel-mode




How to Install and Use TMS XData v4.6.0.1 with Delphi XE2- Delphi 10.3.2 Rio




To install and use TMS XData v4.6.0.1 with Delphi XE2- Delphi 10.3.2 Rio, you need to follow these steps:



  • Download the latest version of TMS XData from the [product page]. You will need a valid license to use it.



  • Extract the downloaded zip file to a folder of your choice.



  • Run the Setup.exe file and follow the instructions to install TMS XData on your machine.



  • Open Delphi IDE and go to Tools > Options > Delphi Options > Library.



  • Select 32 Bits platform and add the path to the TMS XData source folder (e.g. C:\TMS XData\Source) to the Library path.



  • Select 64 Bits platform and add the same path to the Library path.



  • Restart Delphi IDE to apply the changes.



  • Create a new VCL Forms Application project in Delphi.



  • Add a new unit to the project and save it as Server.pas.



In the Server.pas unit, add the following uses clause:


uses System.SysUtils, System.Classes, Sparkle.HttpServer.Module, Sparkle.HttpSys.Server, XData.Server.Module, XData.Comp.Server;


In the Server.pas unit, add a new class declaration as follows:


type TXDataServer = class private FHttpServer: THttpSysServer; FXDataServer: TXDataServerModule; public constructor Create; destructor Destroy; override; procedure Start; procedure Stop; end;


In the Server.pas unit, add the implementation of the TXDataServer class as follows:


TXDataServer constructor TXDataServer.Create; begin inherited Create; FHttpServer := THttpSysServer.Create; FXDataServer := TXDataServerModule.Create(nil); FXDataServer.BaseUrl := ' FXDataServer.Server := FHttpServer; end; destructor TXDataServer.Destroy; begin FXDataServer.Free; FHttpServer.Free; inherited Destroy; end; procedure TXDataServer.Start; begin FHttpServer.Start; end; procedure TXDataServer.Stop; begin FHttpServer.Stop; end;


In the Server.pas unit, add a new variable declaration as follows:


var XDataServer: TXDataServer;


In the Server.pas unit, add the initialization and finalization sections as follows:


initialization XDataServer := TXDataServer.Create; finalization XDataServer.Free;


  • Add a new unit to the project and save it as Model.pas.



In the Model.pas unit, add the following uses clause:


uses Aurelius.Mapping.Attributes;


In the Model.pas unit, add a new class declaration as follows:


[Entity, Automapping] TCustomer = class strict private FId: integer; FName: string; FTitle: string; FBirthday: TDateTime; public property Id: Integer read FId write FId; property Title: string read FTitle write FTitle; property Birthday: TDateTime read FBirthday write FBirthday; end;


In the Model.pas unit, add the following uses clause to the interface section:


uses XData.Service.Common;


In the Model.pas unit, add a new class declaration as follows:


[ServiceContract] ICustomerService = interface(IInvokable) ['B0F3C8F9-8E5A-4C1C-9E7D-1B7F6A0B5E9A'] [HttpGet] function GetCustomers: TList; [HttpGet] function GetCustomer(Id: Integer): TCustomer; [HttpPost] procedure AddCustomer(Customer: TCustomer); [HttpPut] procedure UpdateCustomer(Customer: TCustomer); [HttpDelete] procedure DeleteCustomer(Id: Integer); end;


In the Model.pas unit, add a new class declaration as follows:


type [ServiceImplementation] TCustomerService = class(TInterfacedObject, ICustomerService) public function GetCustomers: TList; function GetCustomer(Id: Integer): TCustomer; procedure AddCustomer(Customer: TCustomer); procedure UpdateCustomer(Customer: TCustomer); procedure DeleteCustomer(Id: Integer); end;


In the Model.pas unit, add the implementation of the TCustomerService class as follows:


TCustomerService function TCustomerService.GetCustomers: TList; begin // TODO: Implement this method to return a list of customers from the database end; function TCustomerService.GetCustomer(Id: Integer): TCustomer; begin // TODO: Implement this method to return a single customer by id from the database end; procedure TCustomerService.AddCustomer(Customer: TCustomer); begin // TODO: Implement this method to insert a new customer into the database end; procedure TCustomerService.UpdateCustomer(Customer: TCustomer); begin // TODO: Implement this method to update an existing customer in the database end; procedure TCustomerService.DeleteCustomer(Id: Integer); begin // TODO: Implement this method to delete a customer by id from the database end;


  • Add a new unit to the project and save it as Main.pas.



  • In the Main.pas unit, add a new form to the project and save it as MainForm.



  • In the MainForm, add a button and set its Caption property to 'Start Server'.



  • In the MainForm, add another button and set its Caption property to 'Stop Server'.



In the MainForm, double-click on the Start Server button and add the following code to its OnC


About

Welcome to the group! You can connect with other members, ge...

Members

bottom of page