新建
DataSnap REST Application
勾上 Simplified Dispatcher
选择 TDSServerModule (如果选择 TComponent,第一次点 Open Browser 看内容时候,会报错。虽然没啥影响,但总是不舒服。)
之后改一下代码
unit ServerMethodsUnit1;
interface
uses System.SysUtils, System.Classes, System.Json,
DataSnap.DSProviderDataModuleAdapter,
Datasnap.DSServer, Datasnap.DSAuth;
type
TServerMethods1 = class(TDSServerModule)
private
{ Private declarations }
public
{ Public declarations }
function EchoString(Value: string): string;
function ReverseString(Value: string): string;
// 好像函数的起头代表了隐藏能力。以 Test 函数为例。
// Get Test
// Post updateTest
// Delete cancelTest
// Put acceptTest
end;
implementation
{$R *.dfm}
uses System.StrUtils, Data.DBXPlatform;
function TServerMethods1.EchoString(Value: string): string;
begin
if string.IsNullOrEmpty(Value) then
Value := GetInvocationMetadata.QueryParams.Values['Value'];
Result := Value;
end;
function TServerMethods1.ReverseString(Value: string): string;
begin
if string.IsNullOrEmpty(Value) then
Value := GetInvocationMetadata.QueryParams.Values['Value'];
Result := System.StrUtils.ReverseString(Value);
end;
end.
于是 RESTDebugger 就可以支持
http://localhost:8080/datasnap/rest/TServerMethods1/EchoString?value=123
http://localhost:8080/datasnap/rest/TServerMethods1/EchoString/123
DSRESTWebDispatcher1 改一下
DSContext : api/
RESTContext : v1/
http://localhost:8080/api/v1/TServerMethods1/EchoString?value=123
感觉在 OnParsingRequest 里还可以做一些修改。
比如:http://localhost:8080/api/v1/EchoString?value=123
应该就是在这里做判断,并修改成“真”的内容。(未试验)