首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在mORMot中配置REST资源

在mORMot中配置REST资源
EN

Stack Overflow用户
提问于 2015-09-17 18:45:03
回答 1查看 1K关注 0票数 0

我希望根据有关mORMot中REST路由的信息(MORMot)配置对REST资源的非常简单的访问。

我需要以localhost/api/apservice/station/1的形式调用url,但是下面的代码只适用于作为localhost/api/apservice/station?stationid={stationid}调用

代码语言:javascript
复制
  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
  • localhost/api/apservice/station/groups return all groups from station
  • localhost/api/apservice/customers/{aCustomerId}/reports/orders/{aOrderNumber}/details?Filter={aDetailFilter}‘
EN

回答 1

Stack Overflow用户

发布于 2016-09-05 19:23:09

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

关于自定义路由,请参见框架文件

重写两个相应的方法:

代码语言:javascript
复制
 TSQLRestServerURIContext = class
  protected
 ...
    /// retrieve interface-based SOA
    procedure URIDecodeSOAByInterface; virtual; abstract;
    /// direct launch of an interface-based service
    procedure ExecuteSOAByInterface; virtual; abstract;

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

代码语言:javascript
复制
type
  TMyRestServer = class(TSQLRestServerFullMemory)
   (...)
  published
    procedure apservice(Ctxt: TSQLRestServerURIContext);
  end;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32637805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档