Push data in body payload using ORACLE REST APIs

How to push data in body payload using ORACLE REST APIs?

 Working with ORACLE REST is really enjoyable and easy, of course. But if you have huge amount of data to push through the web service then it becomes hectic because whatever you push through the web service appended into the URL. And as it’s obvious URL has it’s limitations of length. To push huge amount of data we can use body payload. let’s see what we have in body payload. 

  • form-data
  • x-www-form-urlencoded
  • raw
  • binary

payload option “raw” is useful to push the huge amount of data in payload.

So, data can be pushed through raw payload option. now challenge is to retrieve the data at API other end.

ORDS REST provides support for default body payload parameter using “:body”. Now let’s understand how it works.

When we push data in body payload, it converts into blob format. Hence we need to convert this data into plain text so that we use it for our logical program. 

   l_body_to_clob   CLOB;
   l_plain_text     VARCHAR2 (4000);
   l_body_to_clob := EMPTY_CLOB ();
   DBMS_LOB.createtemporary (l_body_to_clob, TRUE);
   -- Convert body data into CLOB base64
   l_body_to_clob := apex_web_service.blob2clobbase64 ( :body);
   -- convert base64 clob data to plain text
   l_plain_text :=
      UTL_RAW.cast_to_varchar2 (
         UTL_ENCODE.base64_decode (UTL_RAW.cast_to_raw (l_body_to_clob)));
   -- printing  received data
   HTP.p (l_plain_text);
      HTP.p (SQLERRM);

Packages used and their purposes.
It is used to convert the payload data into base64 clob.
Casting raw data to varchar2
To decode raw data.
Casting clob data as raw.

API calling using Postman. 

Related Posts

Leave a Reply