0

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

我需要调用 url as localhost/api/apservice/station/1,但下面的代码仅适用于调用 aslocalhost/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/station/1 -return details for station=1
  • 本地主机/api/apservice/站/组 -return all groups from station
  • localhost/api/apservice/customers/{aCustomerId}/reports/orders/{aOrderNumber}/details?Filter={aDetailFilter}'
4

1 回答 1

1

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

请参阅有关自定义路由的框架文档。

覆盖两个对应的方法:

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

或者定义一个基于方法的服务,它允许您定义任何路由:

type
  TMyRestServer = class(TSQLRestServerFullMemory)
   (...)
  published
    procedure apservice(Ctxt: TSQLRestServerURIContext);
  end;
于 2016-09-05T19:23:09.020 回答