Skip to Main Content

Thursday, October 8, 2020 #PUBLISHED_BY#

Push data in body payload using ORACLE REST APIs

ORDS

Preview

Working with ORACLE REST is really enjoyable and easy ofcourse. 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.

  1. form-data
  2. x-www-form-urlencoded
  3. raw
  4. 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.

DECLARE
   l_body_to_clob   CLOB;
   l_plain_text     VARCHAR2 (4000);
BEGIN
   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);
EXCEPTION
   WHEN OTHERS
   THEN
      HTP.p (SQLERRM);
END;

Packages used and their purposes.
apex_web_service.blob2clobbase64
It is used to convert the payload data into base64 clob.
UTL_RAW.cast_to_varchar2
Casting raw data to varchar2
UTL_ENCODE.base64_decode
To decode raw data.
UTL_RAW.cast_to_raw
Casting clob data as raw.

 

API calling using Postman.

Original Post

Pagination

Comments

  • Test 4 Nov 2020

    tes