#1 2018-10-08 07:47:58

jaclas
Member
Registered: 2014-09-12
Posts: 215

Get available webapi from server

I have an example server:

  TMyService = class(TInterfacedObject, IMyService)
  public
    procedure GetSomeData(const ID: integer; out Data: TSomeData);
    procedure GetOtherData(const ID: integer; out Data: TOtherData);
  end;

  aModel := TSQLModel.Create([]);
  try
    // create a fast in-memory ORM server
    aRest := TSQLRestServerFullMemory.Create(aModel,'',false,false);
    try
      aRest.ServiceRegister(TMyService,[TypeInfo(IMyService)],sicShared);
      aServer := TSQLHttpServer.Create('8090', [aRest], '+', useHttpApiRegisteringURI);
      try
        writeln('Background server is running'#10);
        write('Press [Enter] to close the server.');
        ReadLn;
      finally
        aServer.Free;
      end;
    finally
      aDB.Free;
    end;

Is there a method/function to get from the server information about the available API in the form of a list of simple links for a specific service?

Something like that:

var
 list : TStringList;
 
list := server.GetAvailableAPI('MyService');

//or maybe

list := aRest.GetAvailableAPI('https://server.adrress.com', 'MyService');

in list:

 https://server.adrress.com:8090/root/MyService/GetSomeData
 https://server.adrress.com:8090/root/MyService/GetOtherData

I particularly care about combining the http address (with port if <> 80 or 443), root address, service name and method name.

Offline

#2 2018-10-08 09:35:06

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

Re: Get available webapi from server

If you need to publish the services information to clients, check https://synopse.info/files/html/Synopse … #TITLE_482

For security reasons, there is no such thing as service discovery by default.
You have an optional TSQLRestServer.ServicesPublishedInterfaces/TSQLRestClientURI.ServicePublishOwnInterfaces mechanism, but it is not used on production yet on our side, so it may not be fully working.
And it is for a given TSQLRest (root/model).

If you need it, service discovery should be done in your own code, with a dedicated endpoint.
Note that what is expected with mORMot SOA is to use pascal interfaces as contract.
So interfaces (and their contract - see TInterfaceFactory.Contract) may be the main parameters in this service.

Anyway, service discovery is a mess usually in SOA - from our experiment.
A stateless architecture based on MicroServices is much better (IMHO).

Offline

#3 2018-10-08 10:03:02

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Get available webapi from server

No, no, I need this for own convenience, only for internal use. For easier testing of clients written on other platforms.
Now I have to fold these addresses manually and I'm often wrong, I'm wasting many time.

Last edited by jaclas (2018-10-08 10:04:11)

Offline

#4 2018-10-08 11:04:58

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

Re: Get available webapi from server

Try to define all those addresses in code.
This is called https://en.wikipedia.org/wiki/Infrastructure_as_Code
You can use plain object pascal for it.

All my projects define all the servers as high-level Delphi types, like enumerates (one enum item per daemon, one per service, etc...), with all ports, and root defined in code.
Then client and server code uses this shared code as reference.

Offline

#5 2018-10-08 12:02:11

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Get available webapi from server

Maybe we do not understand a bit.
I'm doing an HTTP server with several REST servers that have dozens of methods.
Now a colleague who is going to write a JS or PHP client asks me for an API.
What should I give him? Pascal files with data types and interface definitions?

Offline

#6 2018-10-08 12:50:22

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

Re: Get available webapi from server

Did you read https://synopse.info/files/html/Synopse … #TITLE_482 ?

You can generate the API documentation directly from the server - or even client code if you write the good Mustache template for the client language and libraries.

Offline

#7 2024-05-14 01:01:50

Lauri
Member
From: Under a rock
Registered: 2020-12-05
Posts: 25

Re: Get available webapi from server

I'm also interested in this subject.
The referred link is broken and title_482 no longer exists. What was the topic?
What is equivalent link in v2 documentation?

Offline

#8 2024-05-14 09:57:35

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

Re: Get available webapi from server

I guess the link is now https://synopse.info/files/html/Synopse … #TITLE_491
"17.2. Generating client wrappers"

Offline

Board footer

Powered by FluxBB