Search code examples
restweb-servicescordovaoracle-apexoracle-ords

How to enable Rest enabled SQL from apex and use it in a cordova app


I'm new to programming with REST enabled SQL of apex. I want this to be called or used in a cordova app I'm developing.

What should I do? Or what should I be knowing to achieve this? What are the steps I should follow to access Apex server in Cordova app


Solution

  • Just so my answer makes sense let me out line the tech stack you are talking about.

    HTTP Request -> ORDS -> DB -> APEX Engine

    ORDS ( oracle.com/rest ) is what provides all the http(s) handling and execution of rest-sql, rest apis, and the call into the APEX engine

    This is done via JDBC Connection Pooling to the Oracle Database Server.

    APEX itself is a plsql based engine inside the database. So, there really isn't an 'apex server'

    Now to the more direct question. How to enable REST SQL. In the ORDS default.xml configuration file add this:

    <entry key="restEnabledSql.active">true</entry>
    

    Once that is enabled, the feature will be available.

    Here's a cURL command to test.

    curl -X "POST" "http://localhost:9090/ords/klrice/_/sql" \
          -H 'Content-Type: application/sql' \
          -u 'KLRICE:KLRICE' \
          -d "select * from dual;"
    

    The output>>

    {
       "env":{
          "defaultTimeZone":"America/New_York"
       },
       "items":[
          {
             "statementId":1,
             "statementType":"query",
             "statementPos":{
                "startLine":1,
                "endLine":1
             },
             "statementText":"select * from dual",
             "response":[
    
             ],
             "result":0,
             "resultSet":{
                "metadata":[
                   {
                      "columnName":"DUMMY",
                      "jsonColumnName":"dummy",
                      "columnTypeName":"VARCHAR2",
                      "precision":1,
                      "scale":0,
                      "isNullable":1
                   }
                ],
                "items":[
                   {
                      "dummy":"X"
                   }
                ],
                "hasMore":false,
                "limit":1500,
                "offset":0,
                "count":1
             }
          }
       ]
    }
    

    Also here's a blog post with more details http://krisrice.io/2017-09-06-ords-173-beta-introducing-rest-enabled/