0

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.

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}

  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? I need examples for:

  • localhost/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}'
SpanishBoy
  • 2,105
  • 6
  • 28
  • 51

1 Answers1

1

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;
Arnaud Bouchez
  • 42,305
  • 3
  • 71
  • 159