All you need to do is create your service contract interface with the operations you want (PUT, POST, etc.) and the routes.
[ServiceContract]
[Route('customers')]
ICustomerService = interface(IInvokable)
['{D2981778-B681-4D4B-B95E-9816B5C7F1D1}']
[HttpPost, Route('')]
procedure CreateCustomer(Customer: TCustomer);
[HttpGet, Route('')]
function GetCustomers: TList<TCustomer>;
[HttpGet, Route('{Id}')]
function GetCustomer(Id: Integer): TCustomer;
[HttpPut, Route('{Id}')]
procedure UpdateCustomer(Id: Integer; Customer: TCustomer);
[HttpDelete, Route('{Id}')]
procedure DeleteCustomer(Id: Integer);
end;
Then create the service implementation for that interface with your custom code that will receive and return parameters. As you said, doesn't matter if you use Aurelius, FireDAC, or anything else, even non-database related. An example for GetCustomers
:
function TCustomerService.GetCustomers: TList<TCustomer>;
var
Customer: TCustomer;
begin
Result := TList<TCustomer>.Create;
TXDataOperationContext.Current.Handler.ManagedObjects.Add(Result);
Query.SQL.Text := 'SELECT * FROM CUSTOMERS';
Query.Open;
while not Query.Eof do
begin
Customer := TCustomer.Create;
TXDataOperationContext.Current.Handler.ManagedObjects.Add(Customer);
Result.Add(Customer);
Customer.Id := Query.FieldByName('ID').AsInteger;
Customer.Name := Query.FieldByName('NAME').AsString;
Customer.Country := Query.FieldByName('COUNTRY').AsString;
Query.Next;
end;
end;
In this case Query
is just a shortcut for a TFDQuery
component in a data module:
procedure TCustomerService.AfterConstruction;
begin
inherited;
DB := TDatabaseModule.Create(nil);
end;
function TCustomerService.GetQuery: TFDQuery;
begin
Result := DB.FDQuery1;
end;
The full working sample project is attached here:
firedac-sql.zip (18.9 KB)