ThatJeffSmith

REST Enabling Your Tables: Insert Rows via POST

Tell Others About This Story:

One of the coolest features of Oracle REST Data Services v3.0 and higher, is the ability to REST enable your Oracle tables and views.

You get a full REST api on your table – INSERT, UPDATE, DELETE, Select with or without predicates and sorting, and getting metadata. You can also batch load records.

I’ve talked about the SELECT and GET bits before.

What I’m going to show today is how to POST (INSERT) up a new record without writing any SQL.

Pre-Requisites

You have Oracle REST Data Services v3 or higher running.

You have REST enabled your Schema.

Your table has a primary key.

You have REST enabled your table.

REST enabled, check. Primary key, check.

REST enabled, check. Primary key, check.

Ok, let’s post up a new record.

The docs show us how.


3.3.1.7 Insert Table Row
This example inserts data into the object. The body data supplied with the request is a JSON object containing the data to be inserted.

If the object has a primary key, then there must be an insert trigger on the object that populates the primary key fields. If the table does not have a primary key, then the ROWID of the row will be used as the item’s identifier.

If the object lacks a trigger to assign primary key values, then the PUT operation described in Update/Insert Table Row should be used instead.

Pattern: POST http://:/ords///

Example:

POST http://localhost:8080/ords/ordstest/emp/
Content-Type: application/json

{ “empno” :7, “ename”: “JBOND”, “job”:”SPY”, “deptno” :11 }

So let’s go do that.

Don't forget to set the content type!

Don’t forget to set the content type!

Now in the ‘religion’ of REST, everything is about the hyperlinks.

So what will our response be?

So, let's go GET it.

So, let’s go GET it.

Here’s the record.

Ta-da.

Ta-da.

A Few More Things

These are simple data types. We support complex ones too, including SPATIAL and GEO-JSON. You’ll need the latest version of ORDS for this.

You can upload multiple records too.

And I can UPDATE my existing record 🙂

PUT, not POST. And you supply the record in the URI via the PK value.

PUT, not POST. And you supply the record in the URI via the PK value.

Related Posts Plugin for WordPress, Blogger...
Tell Others About This Story:

Similar Posts by Content Area: , ,