I set up a REST server using Delphi webbroker and all seem to be working fine except:
I am displaying a DBGrid in the client and I can insert a record (POST request to the server): the server assigns a value for the primary key. How should I send the value of the primary key back to the clioent so thet primary key value becomes (automatically) visible in the grid ?
Currently the POST is returning a JSON with the full content of the inserted record (including the primary key value), but that does not seem to work.
Also: when the server would be changing some other fieldvalues: can these fields be updated automatically as well in the DBGrid ?
Thanks
I assume you use a TWebClientConnection connected to your TWebClientDataSet.
When update POST requests are done, this should trigger WebClientConnection.OnDataReived with the server response as text and also OnGetDataPayload with the server response as object. From there, you could do custom updating based on the server response.
Hi Bruno,
It seems the OnDataReceived of the WebClientConnection is not being triggered when the POST call is returning data.
The OnDataReceived only seems to be called for the GET statement (selecting the data from the database)
OnGetDataPayload is also only called for the initial GET and not after a POST
Additionally: if I could use these methods and I would write the primary key value to the TWebClientDataset: how will I make sure it will not be in the delta data and will not be sent to the server again when doing another applyupdates ?
And the POST request gets executed?
Yes,
The POST request gets executed succesfully: it stores the data in the database and returns a applictaion/json with the full record, and a statuscode 200
This is just the code: The memo gets filled on a GET, but is not triggered after a POST, nor PUT or DELETE
procedure TForm1.WebClientConnection1DataReceived(Sender: TObject;
ARequest: TJSXMLHttpRequestRecord; var AResponse: string);
begin
WebMemo1.Lines.Clear;
WebMemo1.Lines.Add(AResponse);
end;
procedure TForm1.WebClientDataSet1AfterPost(DataSet: TDataSet);
var res: Boolean;
begin
TAwait.ExecP<boolean>(WebClientDataset1.ApplyUpdatesAsync);
end;
Just to make sure it was not related to my REST server I tried a very small demo app that connects to https://jsonplaceholder.typicode.com/posts
The events Bruno mentionned are not being called
The same result: I can't find any way to react to feedback provided by the REST server after a POST, PUT, ... which in my case makes databinding unusable as I can't provide feedback in the server to the client in case of server validation errors, etc, ...
UPDATE: not sure what was wrong, but got it working now.
I can confirm the OnGetDataPayload is being triggered and a cast of the variable aPayload to a string is returning the JSON the backend returned.
The OnDataReceived however is still only being called on the initial GET request.