Here's the case we'll work on using the following example:
The case is : How to Update specific data from EMP_TABLE using API ?
The Fix: Using PUT 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 .
The case is : How to Update specific data from EMP_TABLE using API ?
The Fix: Using PUT 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 .
- 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/:id');
-----------------
ORDS.DEFINE_HANDLER(P_Module_Name => 'emp',
P_Pattern => 'dml/:id',
P_Method => 'PUT',
P_Source_Type => 'plsql/block',
P_Source => 'BEGIN
UPDATE EMP_TABLE
SET Name = :Name
WHERE Id = :id;
COMMIT;
:P_Status := SQLERRM;
END;',
p_mimes_allowed => '',
P_Items_Per_Page => 0);
-----------------
ORDS.DEFINE_PARAMETER(P_Module_Name => 'emp',
P_Pattern => 'dml/:id',
P_Method => 'PUT',
p_name => 'id',
p_bind_variable_name => 'id',
p_source_type => 'HEADER',
p_param_type => 'INT',
p_access_method => 'IN');
-----------------
ORDS.DEFINE_PARAMETER(P_Module_Name => 'emp',
P_Pattern => 'dml/:id',
P_Method => 'PUT',
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:
- Employee Id = 1 was UPDATED from EMP_TABLE
- P_Status Parameter defined to return message after inserting data
To run POST request :
- Click YARC extension from google chrome
- In the URL add: http://localhost:8080/ords/trest/emp_data/dml/1
- Choose from the list : PUT
- In Payload,add the new data: {"Name":"Ismael"}
you should get reply of 200 and the following message:
{
"P_Status": "ORA-0000: normal, successful completion"
}
In the next post, we'll create DELETErequest.
No comments:
Post a Comment