How to limit RestApi access (multiple services)

One more question about RO Rest implementation:
Lets say we have a server with two rest services (implementations). One HttpServer with two TROHttpApiDispatchers. The Dispatchers have different paths (eg. “/config/” and “/command/”). If i point with browser now to “localhost:8099/config” or “localhost:8099/command” i get swagger output from both services with both urls. How can one avoid (limit to each service methods) this?
Thanks!

Hi,

TROHttpApiDispatcher is designed to handle all services.
by other words, it works on global (i.e. whole server) level.

So - such approach is not possible? Even with two http servers or similar? One will see all service methods if he has one path? Even more he could consume both service with a Rest client?

Hi,

You may try to play with custom RODL reader.

something like:

  • ROHttpApiDispatcher1.Server := nil;
  • ROHttpApiDispatcher2.Server := nil;
  • server.Active := True;
  • assign server.OnGetRODLReader. in this event you should return descendant of TROCustomRODLReader that will return only specified service in RODLLibrary, say Service1
  • ROHttpApiDispatcher1.Server := server;
  • activate ROHttpApiDispatcher1
  • assign server.OnGetRODLReader. in this event you should return descendant of TROCustomRODLReader that will return only specified service in RODLLibrary, say Service2
  • ROHttpApiDispatcher2.Server := server;
  • activate ROHttpApiDispatcher2

this may work. because TROHttpApiDispatcher uses RODL returned by server.

you can get current RODLLibrary in RODL based server with

lib := GetRodlLibrary(nil);

for CodeFirst server, things are a bit more complicated

for a long time i use just CodeFirst Server :wink:

Hi,

get autogenerated RODL just after server.Active := True; and later use it in TROCustomRODLReader.

lib := GetRodlLibrary(server.RTTIReader);