2015-09-17 34 views
0

我想根据关于mORMot中REST路由的信息(http://synopse.info/forum/viewtopic.php?id=1833)配置对REST资源的非常简单的访问。在mORMot中配置REST资源

我需要调用网址为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; 

请告知我怎样才能正确地配置REST路由到我的资源?我需要的例子:

  • 本地主机/ API/apservice /站/ 1 - return details for station=1
  • 本地主机/ API/apservice /站/组 - return all groups from station
  • 本地主机/ API/apservice /客户/ {aCustomerId}/reports/orders/{aOrderNumber}/details?Filter = {aDetailFilter}'
+0

难道就没有任何可以配置方便路由能力> – SpanishBoy

回答

0

您可以定义自己的路由类。

请参阅the framework documentation关于自定义路由。

覆盖两个相应的方法:

TSQLRestServerURIContext = class 
    protected 
... 
    /// retrieve interface-based SOA 
    procedure URIDecodeSOAByInterface; virtual; abstract; 
    /// direct launch of an interface-based service 
    procedure ExecuteSOAByInterface; virtual; abstract; 

或定义method-based service,它允许任何路由可以定义:

type 
    TMyRestServer = class(TSQLRestServerFullMemory) 
    (...) 
    published 
    procedure apservice(Ctxt: TSQLRestServerURIContext); 
    end;