Skip to Main Content

ORDS, SODA & JSON in the Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Restful API :body variable

SaraBJun 2 2015 — edited Jun 10 2015

Hi

We have a number of RESTful APIs that we've written and are now in use. These all seem to work fine and the POST and PUT APIs all use the built-in variables that are created from the request body. For example, if the request body is

{"display_name":"My Big Company Name"}

then the API code refers to :display_name to get the value.

To make the APIs more robust and to help support our clients we want to add some debug code to record what the users are sending in the request body. For this the obvious thing to use is :body which stores the request body as a BLOB. However, if you so much as look at :body it is set to null and so are all the built-in variables, regardless of the order you do things in.

So say we had code that used the request body above:

begin

   update my_table

   set      display_name = :display_name

   where  id = :ID;

end;

ID is specified in the API URL as {ID} and this all works fine. But if we change the code to be:

begin

   update my_table

   set      display_name = :display_name

   where  id = :ID;

   insert into my_debug_table (request_body) values (:body);

end;

This doesn't work and :display_name is null. This can be seen in a simpler example, if you have a POST API and pass anything in the body then have your API code as:

begin

  htp.p(dbms_lob.getlength(:body)||' - '||dbms_lob.getlength(:body));

end;

You will see the output as n - 0 where n is the length of your request body and 0 is what it's set to after you've touched it.

Obviously all this code is greatly simplified. Our API requests have large JSON objects, lots of variables, validations and processing which is why storing the request body would be so useful to us. What I can't figure out is why all the variables are set to null even if you reference :body at the end of the code.

I have tried googling and searching the forum, but there is very little information available on these variables.

So is there a way to use the variables and also the :body? And why does everything get set to null?

Many thanks for your help

Sara

PS. Also posted in APEX forum Restful API :body variable as using APEX 4.2.5 and also tested in APEX 5.

Comments

Anand...

Hi,

I think you can definitely set default service for server side load  balancing without an issue. Are you facing issue while using default service?Did you check the number of session  based on service_name from gv$session?

Anand

User511360-OC

Hello. At the moment I couldn't even change this service's properties:

sql>select name, goal, clb_goal from dba_services where name='MYDB';

NAME       GOAL  CLB_G

----------        -----      -----

MYDB                  LONG

So, I try to change CLB_GOAL to 'short' I got an error:

$srvctl modify service -s MYDB -d MYDB -j SHORT

PRKO-2120 : The internal database service MYDB cannot be managed with srvctl

Or are there other ways to change this ?

1 - 2
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 8 2015
Added on Jun 2 2015
2 comments
2,356 views