Show/Hide Toolbars

TMS XData Documentation

TMS XData is a full-featured Delphi framework that allows you to create REST/JSON servers, using server-side actions named service operations, and optionally exposing TMS Aurelius entities through REST endpoints.. 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;
    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;


With a few lines of code you can create an XData server to expose these objects. 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 a POST method to create new objects, DELETE to remove objects, and PUT or PATCH to update the objects. The following example will change the value of the FTitle property of the customer resource specified in the previous example:


PATCH /tms/xdata/Customer(1) HTTP/1.1
Host: server:2001

  "Title": "Marketing Manager" 


You can also perform queries on existing objects. The following example will retrieve all customers with a country name equal to "USA", ordered by the customer's name.


GET /tms/xdata/Customer?$filter=Country/Name eq 'USA'&$orderby=Name&$top=10 HTTP/1.1

Host: server:2001


The server will return a JSON array of objects containing all the filtered objects. You can use query paging to restrict the number of objects returned in each request.


Also, you can use service operations to implement custom business logic that uses Aurelius objects. By defining an interface and an implementation...


  IMyService = interface(IInvokable)
    function GetTopCustomersByState(const State: string): TList<TCustomer>;
function TMyService.GetTopCustomersByState(const State: string): TList<TCustome>;
  Result := TXDataOperationContext.Current.GetManager.Find<TTCustomer>
    .Where(TLinq.Eq('State', State) and TLinq.Eq('Category', TStatus.VIP))
end; can easily invoke them from a Delphi client...


Client := TXDataClient.Create;
Client.Uri := 'http://server:2001/tms/xdata';
MyService := Client.Service<IMyService>;
TopNYCustomers := MyService.GetTopCustomersByState('NY');
// process customers


...or from an HTTP client:


POST /tms/xdata/MyService/GetTopCustomersByState HTTP/1.1
Host: server:2001
  "State": "NY"


Please refer to the Introduction topic of this manual which lists all major topics to learn more about XData and its features.