2015-09-17 49 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;