Search code examples
oracle-apexoracle-ords

Dynamic backend for Oracle Apex Rest Enables SQL


I am building an application in Oracle Apex. The idea is to be a frontend to multiple databases, all of which have the same schema objects.

To do this, I would like to use Rest Enabled SQL to build out the pages I need, then somehow swap the database used for the actual data at run time. The basic idea looks a little like this:

DB1 ----+
        |
DB2 ----+---> Rest Enabled SQL ---> Apex page
        |
DB3 ----+

So at runtime, a user would be able to select between DB1, DB2 and DB3 as the source of the data for the page they are looking at.

What I am having difficulty with is how to associate the user's session with the requests to the Rest Enabled SQL end point. I have printed out the headers, and there is nothing that I can use that identifies the user session.

I would like to know if it is possible to do one of the following:

  1. Inject a header per request for all Rest Enabled SQL calls (this could be a session ID or similar)
  2. Define the Rest Enabled SQL data source with some kind of dynamic query parameter.
  3. "Rewrite" the definition of the Rest Enabled SQL data source somehow on a per session basis so that it can have the session information available to it.

I have tried using the initialization code in the Rest Enabled SQL definition, but that only runs after the Api request has been sent.


Solution

  • I have managed to solve this by investigating the body of the request in my end point, and it contains the user ID the initiated the request, so I am able to switch on that based on some logic in the application.