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 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.
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.
1DECLARE 2 l_body_to_clob CLOB; 3 l_plain_text VARCHAR2 (4000); 4BEGIN 5 l_body_to_clob := EMPTY_CLOB (); 6 DBMS_LOB.createtemporary (l_body_to_clob, TRUE); 7 -- Convert body data into CLOB base64 8 l_body_to_clob := apex_web_service.blob2clobbase64 ( :body); 9 -- convert base64 clob data to plain text 10 l_plain_text := 11 UTL_RAW.cast_to_varchar2 ( 12 UTL_ENCODE.base64_decode (UTL_RAW.cast_to_raw (l_body_to_clob))); 13 -- printing received data 14 HTP.p (l_plain_text); 15EXCEPTION 16 WHEN OTHERS 17 THEN 18 HTP.p (SQLERRM); 19END;
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.