繁体   English   中英

在mORMot中配置REST资源

[英]Configuration REST resources in mORMot

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

我需要将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;

请告知我如何正确配置到我的资源的REST路由? 我需要以下示例:

  • localhost / api / apservice / station / 1-站点的return details for station=1
  • localhost / api / apservice / station / groups- return all groups from station
  • 本地主机/ api / apservice / customers / {aCustomerId} /报告/订单/ {aOrderNumber} / details?Filter = {aDetailFilter}'

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

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

覆盖两个对应的方法:

 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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM