You are not logged in.
BREAKING CHANGE in TSQLRestServerCallBackParams use: all method-based services should now be a procedure, and use aParams.Results()/Error() methods to return the content - new definition of aParams features now full access to incoming/outgoing context and parameters.
See http://synopse.info/fossil/info/ace12b0996
In short:
function TServer.Method(var aParams: TSQLRestServerCallBackParams): integer;
shall be changed into
procedure TServer.Method(var Ctxt: TSQLRestServerCallBackParams);
(here Ctxt is used as parameter name since it was found to be more meaningful)
And instead of setting the HTTP status in result variable and aParams.Resp for returned body content or aParams.ErrorMsg^ in case of error, you have to use Ctxt.Returns() or Ctxt.Results() or Ctxt.Error() new methods.
For instance:
function TSQLRestServerTest.Sum(var aParams: TSQLRestServerCallBackParams): Integer;
var a,b: Extended;
begin
if not UrlDecodeNeedParameters(aParams.Parameters,'A,B') then
begin
result := 404; // invalid Request
aParams.ErrorMsg^ := 'Missing Parameter';
exit;
end;
while aParameters<>nil do
begin
UrlDecodeExtended(aParams.Parameters,'A=',a);
UrlDecodeExtended(aParams.Parameters,'B=',b,@aParams.Parameters);
end;
aParams.Resp := JSONEncodeResult([a+b]);
// same as : aResp := JSONEncode(['result',a+b],TempMemoryStream);
result := 200; // success
end;
shall be changed into the clearer syntax:
procedure TSQLRestServerTest.Sum(var Ctxt: TSQLRestServerCallBackParams);
var a,b: Extended;
if UrlDecodeNeedParameters(Ctxt.Parameters,'A,B') then begin
while Ctxt.Parameters<>nil do begin
UrlDecodeExtended(Ctxt.Parameters,'A=',a);
UrlDecodeExtended(Ctxt.Parameters,'B=',b,@Ctxt.Parameters);
end;
Ctxt.Results([a+b]);
end else
Ctxt.Error('Missing Parameter');
end;
Or even the easier to read/code/understand:
procedure TSQLRestServerTest.Sum(var Ctxt: TSQLRestServerCallBackParams);
begin
with Ctxt do
Results([InputDouble['a']+InputDouble['b']]);
end;
See http://blog.synopse.info/post/2010/07/1 … phi-7-2010 rewritten article.
Offline
WARNING!
New breaking change:
procedure TServer.Method(var Ctxt: TSQLRestServerCallBackParams);
should now be written as:
procedure TServer.Method(Ctxt: TSQLRestServerURIContext);
See http://synopse.info/fossil/info/c28e9e05c2
In fact, TSQLRestServerURIContext is now a true Delphi class, with virtual methods able to change the whole routing and execution scheme of any remote request.
In the close future the basic fixed TServiceRoutingMode = (rmREST, rmJSON_RPC) will certainly be replaced by dedicated classes.
No speed penalty has been observed (on the contrary), and TSQLRestServer.URI() code is now much easier to enhance/maintain.
The main blog article about method-based services and the associated documentation have been updated to reflect this change.
Offline
That's it...
URI routing for interface-based service is now specified by the two TSQLRestRoutingREST and TSQLRestRoutingJSON_RPC classes (inheriting from the abstract TSQLRestServerURIContext class) instead of rmJSON and rmJSON_RPC enums - it allows any custom URI routing by inheritance .
Offline