[英]Configuration REST resources in mORMot
I want to configure pretty simple access to my REST resource, based on information ( http://synopse.info/forum/viewtopic.php?id=1833 ) regarding REST routing in mORMot. 我想基于有关mORMot中REST路由的信息( http://synopse.info/forum/viewtopic.php?id=1833 )配置对REST资源的非常简单的访问。
I need to call url as localhost/api/apservice/station/1
, but code below works only for calling as localhost/api/apservice/station?stationid={stationid}
我需要将url称为
localhost/api/apservice/station/1
,但以下代码仅适用于localhost/api/apservice/station?stationid={stationid}
IAPIService = interface(IInvokable)
['{0F23D411-C3F0-451A-8580-AB5BE6E521E6}']
function Station(StationID: Integer; out Station: TSQLStation): TCQRSResult;
end;
TAPIService = class(TInterfacedObject, IAPIService)
private
fDbConnection : TSQLDBConnectionProperties;
public
constructor Create(const aProps: TSQLDBConnectionProperties ); overload;
public
function Station(StationID: Integer; out Station: TSQLStation): TCQRSResult;
end;
Please advise how can I correctly configure REST routing to my resources? 请告知我如何正确配置到我的资源的REST路由? I need examples for:
我需要以下示例:
return details for station=1
return details for station=1
return all groups from station
return all groups from station
You can just define your own routing class. 您可以只定义自己的路由类。
See the framework documentation about custom routing. 请参阅有关自定义路由的框架文档 。
Override the two corresponding methods: 覆盖两个对应的方法:
TSQLRestServerURIContext = class
protected
...
/// retrieve interface-based SOA
procedure URIDecodeSOAByInterface; virtual; abstract;
/// direct launch of an interface-based service
procedure ExecuteSOAByInterface; virtual; abstract;
Or define a method-based service , which allows any routing you could define: 或定义基于方法的服务 ,该服务允许您定义以下任何路由:
type
TMyRestServer = class(TSQLRestServerFullMemory)
(...)
published
procedure apservice(Ctxt: TSQLRestServerURIContext);
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.