Post, Update and Delete methods

Hello Team;

I was looking at this and wandering how could we use the FD and FDBatch (similar to what is been used in this sample) for HTTP POST/UPDATE/DELETE methods?

I was able to leverage the sample and build the httpget for what I'm looking for, but need to know how we could implement other methods?


You should create a method that receives parameters for the field values, and then execute the SQL statement using FDQuery inside the method implementation.

Hello Wagner;

Do we have any sample of defining the Put / Delete methods ...most of the demos for service call are based on Get and in my use case the client side is not a Delphi. I would like to create a generic services to do the Get and Put functions.

I had a good progress on Get based on the demo but Put / Update / Delete is not yet.

Hello Wagner;

Would you please review my resent question in respect to your respond and get back to me? I would like to see some real implementation for PUT & DELETE & UPDATE methods.

The end result is important; how we could do that (implement it) – using FireDAC or Aurelius is not important for me.


** This electronic message contains information from which may be legally privileged and confidential

I meant to see the real sample for httpPOST, httpDelete, etc.

Thank you for help in advance.

Hello Team; do you have any update on this subject for me?

I need a real sample which shown how we could use the [httppost] / delete / update methods, have a service running under windows and let us to add a record to database by invoking that method outside of Delphi.

Assume the client application is a PHP or C# and they want to call our generic API to add a record, deleted and update by JSON – of course as part of the JSON parameters we have ask them to send us user_name and pass_word so we could validated them against database before execute the request.


** This electronic message contains information from which may be legally privileged and confidential

All you need to do is create your service contract interface with the operations you want (PUT, POST, etc.) and the routes.

  ICustomerService = interface(IInvokable)
    [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);

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>;
  Customer: TCustomer;
  Result := TList<TCustomer>.Create;
  while not Query.Eof do
    Customer := TCustomer.Create;
    Customer.Id := Query.FieldByName('ID').AsInteger;
    Customer.Name := Query.FieldByName('NAME').AsString;
    Customer.Country := Query.FieldByName('COUNTRY').AsString;

In this case Query is just a shortcut for a TFDQuery component in a data module:

procedure TCustomerService.AfterConstruction;
  DB := TDatabaseModule.Create(nil);

function TCustomerService.GetQuery: TFDQuery;
  Result := DB.FDQuery1;

The full working sample project is attached here: (18.9 KB)

1 Like

Wagner; many many thanks. I will explore this and keep you posted if anything else came-up.

At the meantime; I've two Q:

  1. What would the best way to handle the varbinary (in DB world, blob) in methods?
  2. We want to use user/password as parameters when the service is called from client side (when client is not delphi) - considering the fact we would use "https" at production, is it good way to do that or there is other way you recommend based on your experience.

Hello Wagner;

Would you help me to use a proper type casting for loading the TBlob field(s) into table when posting the data?

Assume the table has this structure:


[ID] [int] NOT NULL,

[NAME] nvarchar NULL,

[COUNTRY] varchar NULL,

[RATE] [decimal](6, 4) NULL,



[MAPIMAGE] varbinary NULL,


So the mapping class is something like this:

TCustomer = class

Id: Integer;

Name: string;

Country: string;








I’ve to use a “varbinarry(max)” in my table data field, but not sure what type casing could be used to load them properly in insert?

Query.SQL.Text := 'INSERT INTO CUSTOMERS VALUES (:id, :name, :country, :rate, :code, :createddate, :blobmap)';

Query.ParamByName('id').AsInteger := Customer.Id;

Query.ParamByName('name').AsString := Customer.Name;

Query.ParamByName('country').AsString := Customer.Country;

Query.ParamByName('rate').AsFloat := Customer.Rate;

Query.ParamByName('code').AsString := Customer.CountryCode;

Query.ParamByName('createddate').AsString := Customer.CreatedDate;

Query.ParamByName('blobmap').LoadFromStream(aStream, ftBlob); // .AsAnsiString := Customer.Map.AsUnicodeString;

In JSON call, I could send an image data in base64 encoded data… but no when I decode and inserted to database / table is not a write values.

Thank you.


It could be good to create new different topics for different subjects.

You can read a TBlob using AsUnicodeString, AsBytes, or use SaveToSTream to save the content to a stream. Then you can use such data as you wish with your preferred database component - FireDAC, for example.

Thanks. I've tested that using the SaveToStream and LoadFromStream using blob type / although seems is working but the data saved in the field is not the same as original one passed through the httppost.

I will create a new request | topics for this to get more help.


A post was split to a new topic: Response codes

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.