#5 Your first POST RESTful Service

Here's the case we'll work on using the following example:
The case is : How to Fetch specific data from EMP_TABLE  using API ?

The Fix: Using GET method
Before You Begin: In contrast to GET methods,  all of POST,PUT and DELETE methods   require third party editor to run .
There are many applications for this purpose, you can install any of them using Google Chrome web store  .
YARC may be the simplest one to use , you can download it from here .


  1. Using PLSQL copy the following code:

BEGIN
  -----------------
  ORDS.DEFINE_MODULE(P_Module_Name    => 'emp',
                     P_Base_Path      => 'emp_data',
                     P_Items_Per_Page => 0);
  -----------------
  ORDS.DEFINE_TEMPLATE(P_Module_Name => 'emp', 
                       P_Pattern     => 'dml');
  -----------------
  ORDS.DEFINE_HANDLER(P_Module_Name    => 'emp',
                      P_Pattern        => 'dml',
                      P_Method         => 'POST',
                      P_Source_Type    => 'plsql/block',
                      P_Source         => 'BEGIN 
                                           INSERT INTO EMP_TABLE(Id, Name) 
                                                         VALUES (:Id, :Name); 
                                           COMMIT;
                                           -----------
                                           :P_Status := SQLERRM;
                                           -----------
                                           END;',
          p_mimes_allowed  => '',
          P_Items_Per_Page => 0);
  -----------------
  ORDS.DEFINE_PARAMETER(P_Module_Name        => 'emp',
                        P_Pattern            => 'dml',
                        P_Method             => 'POST',
                        p_name               => 'P_Status',
                        p_bind_variable_name => 'P_Status',
                        p_source_type        => 'RESPONSE',
                        p_param_type         => 'STRING',
                        p_access_method      => 'OUT');   
  COMMIT;
  -----------------
END;
In This POST Request:
  • Data INSERTED into EMP_TABLE
  • P_Status Parameter defined to return message after inserting data
To run POST request :
  1. Click YARC extension from google chrome
  2. In the URL add: http://localhost:8080/ords/trest/emp_data/dml
  3. Choose from the list : POST
  4. In Payload,add the new data: {"Id":1,  "Name":"Omar"}
Once you have finished, click Send Request.
you should get reply of  200 and the following message: 
 {
"P_Status": "ORA-0000: normal, successful completion" }
In the next post, we'll create PUT request.

1 comment:

Remove unused Layouts in Oracle Apex

 Tables used : APEX_XXXXXXX.WWV_FLOW_REPORT_LAYOUTS APEX_XXXXXXX.WWV_FLOW_SHARED_QUERIES use the following query to delete unused Layouts. ...