venerdì 13 maggio 2016

Oracle Rest Data Service & Oracle Cloud (Second Part): How to INSERT (POST) data with REST

In the [FIRST] part you have learned how to create a REST Data Service in Oracle Database (in Cloud)

We have create a SELECT (GET), now we will see how to create an INSERT (POST).

You can use the "auto rest" (more info here) but with this you can do only simple insert, with primary key and only a "select * ..." if you would like to specialized your INSERT (or UPDATE or DELETE) you must do what I will explain in this post.

We will create a Data Service that will insert a row in the "emp" table of the HR user:


This is the configuration:
Insert in the Source field your preferred insert:

begin  
    insert into emp (empno,ename,job,hiredate,sal,deptno) values   
    (:empno,:ename,:job,:hiredate,:sal,:deptno);  
 end; 

This is an example, you can write every kind of complex insert.


 Now you can test it, I suggest to use something like "Postman":

use your url in the POST field:
https://yourIP/ords/pdb1/mariniws/hr/emp/

Set in the Headers tab:
Content-Type: application/json



Select the Body tab and put here the data to send:

 {  
  "empno":1234,  
  "ename":"Marini",  
  "job":"PRESIDENT",  
  "hiredate":"2003-02-01T08:00:00Z",  
  "sal":5000,  
  "deptno":10  
 }  

Click the "Send" button:
If all It is ok, you will receive a Status 200 OK


If you refresh SQL Developer you can find the new row:




5 commenti: