ORDS Scripts

Oracle Application Express is a rapid development tool for Web applications on the Oracle database.
Post Reply
admin
Posts: 1994
Joined: Fri Mar 31, 2006 12:59 am
Location: Pakistan
Contact:

ORDS Scripts

Post by admin »

GET

Code: Select all

declare
l_clob clob;
json_content APEX_JSON.t_values;
v_lines number;

begin
 l_clob:= apex_web_service.make_rest_request(
            p_url => 'https://apex.oracle.com/pls/apex/erpstuffords/hr/dept',
            p_http_method => 'GET',
            p_parm_name => apex_util.string_to_table('deptno'),
            p_parm_value => apex_util.string_to_table(:P3_DEPTNO)
            );      
:P3_JSON := l_clob;
 apex_json.parse(p_values => json_content , p_source => l_clob );

v_lines := APEX_JSON.get_count(p_path => 'items' ,p_values => json_content);

for i IN 1 .. v_lines  loop
 :P3_DNAME := apex_json.get_varchar2(p_path=>'items[%d].dname', p0=> i, p_values=>json_content);
 :P3_LOC := apex_json.get_varchar2(p_path=>'items[%d].loc', p0=> i, p_values=>json_content);
end loop;
end;   


PUT

Code: Select all

declare
    l_clob       CLOB;
BEGIN

    APEX_WEB_SERVICE.g_request_headers(1).name := 'Content-Type';
    APEX_WEB_SERVICE.g_request_headers(1).value := 'application/json';

    l_clob := apex_web_service.make_rest_request(
        p_url => 'https://apex.oracle.com/pls/apex/erpstuffords/hr/dept',
        p_http_method => 'PUT',
        p_body => '{"deptno":' || :P3_DEPTNO || ',"dname":"' || :P3_DNAME || '","loc":"' || :P3_LOC || '"}'
       );

--:P3_LOC := '{"dname":"' || :P3_DNAME || '","loc":"' || :P3_LOC || '"}';

-- Check JSON syntax at https://jsonlint.com/

:P3_JSON := l_clob; 
END;
DELETE

Code: Select all

declare
    l_clob       CLOB;
BEGIN

    APEX_WEB_SERVICE.g_request_headers(1).name := 'Content-Type';
    APEX_WEB_SERVICE.g_request_headers(1).value := 'application/json';
    APEX_WEB_SERVICE.g_request_headers(1).name := 'deptno';
    APEX_WEB_SERVICE.g_request_headers(1).value := :P3_DEPTNO;
    
    l_clob := apex_web_service.make_rest_request(
        p_url => 'https://apex.oracle.com/pls/apex/erpstuffords/hr/dept',
        p_http_method => 'DELETE'
       );

:P3_JSON := l_clob; 
END;
POST

Code: Select all

declare
    l_clob       CLOB;
BEGIN

    APEX_WEB_SERVICE.g_request_headers(1).name := 'Content-Type';
    APEX_WEB_SERVICE.g_request_headers(1).value := 'application/json';

    l_clob := apex_web_service.make_rest_request(
        p_url => 'https://apex.oracle.com/pls/apex/erpstuffords/hr/dept',
        p_http_method => 'POST',
        p_body => '{"dname":"' || :P3_DNAME || '","loc":"' || :P3_LOC || '"}'
       );

--:P3_LOC := '{"dname":"' || :P3_DNAME || '","loc":"' || :P3_LOC || '"}';

-- Check JSON syntax at https://jsonlint.com/

:P3_JSON := l_clob; 
END;
Explanation in youtube videos,

https://youtu.be/p3F7KRSMaao
https://youtu.be/41z9e6zQO5g
https://youtu.be/SQZYExiN_-w
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest