Search code examples
oracle-apexoracle-rest-data-services

How to create RESTful Service in Oracle Apex?


I'm trying to create a RESTful service in Oracle Apex 20.2 as follows:

    RESTful Service Module : api
    Module Base Path : /api/
    URI Template : {command}
    Full URL : http://localhost:8080/ords/useralias/api/{command}
    Method(Value Required) : POST
    Source Type : PL/SQL
    Source : 
            htp.p('Hi !');  

enter image description here

The service is created. However when calling it via Curl using the command:

    curl -X GET http://localhost:8080/ords/useralias/api/something

I'm getting the error :

    {
        "code": "UserDefinedResourceError",
        "title": "User Defined Resource Error",
        "message": "The request could not be processed due to an error in a user defined resource",
        "o:errorCode": "ORDS-25001",
        "cause": "An error occurred when evaluating the SQL statement associated with this resource. SQL Error Code 900, Error Message: ORA-00900: instruction SQL non valide\n",
        "action": "Ask the user defined resource author to check the SQL statement is correctly formed and executes without error",
        "type": "tag:oracle.com,2020:error/UserDefinedResourceError",
        "instance": "tag:oracle.com,2020:ecid/3-WELoSC5oGNk1d3BuOh2A"
    }

Using the exact same service with a "GET" handler and the same source (htp.p('Hi !');), the service works properly.

How can I make it work?


Solution

  • The answer is stupidly simple :

    the source should be :

    begin
        htp.p('hi !');
    end;
    

    instead of :

        htp.p('hi !');