0

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 ルーティングを正しく構成する方法を教えてください。次の例が必要です。

  • ローカルホスト/api/apservice/ステーション/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

独自のルーティング クラスを定義するだけです。

カスタム ルーティングについては、フレームワークのドキュメントを参照してください。

対応する 2 つのメソッドをオーバーライドします。

 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 に答える