Dynimic creation of endpoint / service contract

Hi there
Not sure that this question (I try to do it just for education purpose) relies on XData, may be more suitable chapter is Sparkle...
But anyway, I'll try to exaplian wehat I'm looking for.

In XData we have under XDataServer component property DefaultEntitySetPermissions and according to this automatic endpoints will be accordingly wisible in my server.
There good example also how to implement probably same in code:

  {
    This service contract creates the following endpoints:
      GET /customers              -- Get all customers
      POST /customers             -- Create a customer
      GET /customers/:id          -- Get a specific customer
      PUT /customers/:id          -- Update a customer
      DELETE /customers/:id       -- Delete a customer
  }
  [ServiceContract]
  [Route('customers')]
  ICustomerService = interface(IInvokable)
    ['{D2981778-B681-4D4B-B95E-9816B5C7F1D1}']
    [HttpPost, Route('')]
    procedure CreateCustomer(Customer: TCustomer);
    [HttpGet, Route('')]
    function GetCustomers: TList<TCustomer>;
    [HttpGet, Route('{Id}')]
    function GetCustomer(Id: Integer): TCustomer;
    [HttpPut, Route('{Id}')]
    procedure UpdateCustomer(Id: Integer; Customer: TCustomer);
    [HttpDelete, Route('{Id}')]
    procedure DeleteCustomer(Id: Integer);
  end;

But is it possible somehow to add service contract in code?

More clearly - what if I have 10 + tables with the same structure (id, name fields) and want to add in code / runtime all those table's endpoint (maybe tied to the same implemented functions) so that Swaggger also shows all those separately?
The reason for that - I don't know before hand how much table there are in database...
But any plain registers / lists:
/customers/:id
/automobiles/:id:
/employees/:id
/bids/:id
can be resolved correctly (from right table)..

What I understand so far, I'm able to add any endpoint through TAnonymousServerModule and process responses there....

In case if I not intend to use Aurelius (but result always is some json) probably is there any solution not to hardcode every class / entity but do it in more flexible way.

Thank you in advance.

How about adding the table as a parameter to the five endpoints? And maybe another endpoint to retrieve the list of available tables? And then perhaps just use JSON instead of TCustomer or TList to pass data structures that are not known ahead of time? The table name could be validated in each of the endpoints (with a common function perhaps) and then the JSON could be parsed/generated/mapped to the relevant data structure.

I second @AndrewSimard's suggestion. It's a good approach. Note you can have that parameter in the URL path.

Thanks guys
This way (as parameter = table name) working of cource

But my aim was to get physically for every table these 5 endpoints (including swagger showing table count * 5)

Is it possible do it in pure Sparkle with TAnonymousServerModule ?
What if I add 150 modules in code / loop :slight_smile:

Thanks again

What is "get physically"?
Of course, you can do any endpoints you want using Sparkle and anonymous server module.

But then you will lose all the easiness of XData. Swagger support in XData is awesome because it gets everything automatically from the interfaces: the declaration, the parameters, the documentation, etc. If you don't have an interface for your endpoint, you lose all of that and you will have to do it all manually. Possible, but then it makes no sense imho.

Thus you can create your dynamic endpoints, but it will take more work. You can also create modules dynamically, if you want.