简体   繁体   English

在mORMot中配置REST资源

[英]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: 我需要以下示例:

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

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.

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