#1 2021-04-28 02:53:17

keinn
Member
Registered: 2014-10-20
Posts: 103

can ServiceMethodRegisterPublishedMethods support prefix contain "/"

if it does ,the the uri will be more friendly
eg: domain/root
      domain/root/admin/*
      domain/root/api/*

i know the interface based service can do this ,but some times ,the method based service can be more flexable

Offline

#2 2021-04-28 04:41:32

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

Re: can ServiceMethodRegisterPublishedMethods support prefix contain "/"

At my old employer's place I wrote a method to replace all / in the URI with _ in the method calls. It was quite easy to do and I am planning on doing that again, as this improves readability for the user.

A call from domain/root/admin/user/add would go to the method admin_user_add.

Last edited by sakura (2021-04-28 04:43:05)

Offline

#3 2021-04-28 05:03:29

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

Re: can ServiceMethodRegisterPublishedMethods support prefix contain "/"

Just browsed through some old mORMot 1 test project, haven't done it in mORMot 2 yet. I created an override for TSQLRestServerURIContext.URIDecodeSOAByMethod. Retrieve the URI and URIBlobFieldName, replacing all / with _ and then checking like

type
  TSQLRestServerAccess = class(TSQLRestServer);

...

    MethodIndex := TSQLRestServerAccess(Server).fPublishedMethods.FindHashed(TestURI);

    if MethodIndex >= 0 then
    begin
      URI := TestURI;
      URIBlobFieldName := TestURIBlobFieldName;

      Exit;
    end;

Sorry, can't show all the rest here :-|

Offline

#4 2021-04-28 12:26:45

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: can ServiceMethodRegisterPublishedMethods support prefix contain "/"

Offline

#5 2021-04-28 13:18:09

keinn
Member
Registered: 2014-10-20
Posts: 103

Re: can ServiceMethodRegisterPublishedMethods support prefix contain "/"

why TMVCApplication can register a prefix like "blog" and then can access it with "root/blog/default" ?  i mean, why this feture can not be used in ServiceMethodRegisterPublishedMethods ? any class with its published methods registed with ServiceMethodRegisterPublishedMethods with prefix ,eg "test" ,why we can not access it use "root/test/*" but "root/test*"?

Offline

#6 2021-04-28 13:25:33

keinn
Member
Registered: 2014-10-20
Posts: 103

Re: can ServiceMethodRegisterPublishedMethods support prefix contain "/"

my point is to group all method with one Prefix.
this is not to say i need to register a method with / slash or _ underline

Offline

#7 2021-04-28 13:25:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: can ServiceMethodRegisterPublishedMethods support prefix contain "/"

This is done at the HTTP server level, I guess.
So it should work with methods based services too.

Offline

#8 2021-04-28 13:50:15

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

Re: can ServiceMethodRegisterPublishedMethods support prefix contain "/"

Works like a charm <3

  ServiceManagerApp := TMypServiceManagerApplication.Create;
  ServiceManagerApp.Start(RestServer, TypeInfo(IMypServiceManagerApplication));
  RestServer.ServiceMethodRegisterPublishedMethods('svc_', ServiceManagerApp);

and the App-Class has methods like list_session and may now be called as domain/root/svc/list/session :-)

Offline

#9 2021-04-28 14:31:32

keinn
Member
Registered: 2014-10-20
Posts: 103

Re: can ServiceMethodRegisterPublishedMethods support prefix contain "/"

still get me wrong.
i mean TMVCApplication  alreay have this feture , but any regular class registerd by RestServer.ServiceMethodRegisterPublishedMethods('some') dose not .
eg:

type 
    TMyDemoClass = class
    published 
        procedure list(Ctxt:TSQLRestServerURIContext);
    end;
var
  _demo:TMyDemoClass ;

begin
... rest root eg :root
RestServer.ServiceMethodRegisterPublishedMethods('demo', _demo);
end;

then i need to access the list method by http://domain/root/demo/list
but with current mormot implemention , it only can be accessed by http://domain/root/demolist

Offline

#10 2021-04-28 14:35:53

keinn
Member
Registered: 2014-10-20
Posts: 103

Re: can ServiceMethodRegisterPublishedMethods support prefix contain "/"

sakura wrote:

Works like a charm <3

  ServiceManagerApp := TMypServiceManagerApplication.Create;
  ServiceManagerApp.Start(RestServer, TypeInfo(IMypServiceManagerApplication));
  RestServer.ServiceMethodRegisterPublishedMethods('svc_', ServiceManagerApp);

and the App-Class has methods like list_session and may now be called as domain/root/svc/list/session :-)


your situation is too add one more level suburl to the mvc app above the TMVCRunOnRestServer.Create(Self,nil,'svc');
your case is to rewrite the list_session method to /list/session

Offline

Board footer

Powered by FluxBB