Scott Wan
DBA, software developer
Scott Wan 2017.12.17
Lauched from Wechat, can be shared and ping to home screen without install, have native mobile app function as access camera, GPS devices.
Oracle REST Data Services (ORDS) makes it easy to develop modern REST interfaces for relational data in the Oracle Database, Oracle Database 12c JSON Document Store, and Oracle NoSQL Database. A mid-tier Java application, ORDS maps HTTP(S) verbs (GET, POST, PUT, DELETE, etc.) to database transactions and returns any results formatted using JSON.
CREATE table "TASK" (
"ID" NUMBER GENERATED ALWAYS AS IDENTITY,
"NAME" VARCHAR2(32) NOT NULL,
"DONE" CHAR(1),
constraint "TASK_PK" primary key ("ID")
)
/
alter table "TASK" add
constraint "TASK_UK1"
unique ("NAME")
/
-- GET
select * from task
where id = nvl(:id, id)
and name = nvl(:name, name)
and done = nvl(:done, done)
order by id
-- DELETE
begin
delete from task where id = :id;
:status := 200;
exception
when others then
:status := 400;
end;
-- POST
declare
task_id string(32);
begin
select id into task_id from task where id = :id;
update task set
name = nvl(:name, name),
done = nvl(:done, done)
where id = :id;
:status := 200;
exception
when no_data_found then
insert into task (name, done)
values(:name, 'N')
return id into :id;
:Status := 200;
when others then
:status := 400;
end;
by Chrome extension Restlet Client - REST API Testing
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
todoList: {}
},
//事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad: function () {
wx.request({
url: 'https://<replace with your own api url>/',
success: (res) => {
this.setData({
todoList: res.data
})
}
})
...
<!--index.wxml-->
<view class="container">
<view class="userinfo">
...
</view>
<view class='todo-list'>
<view class='todo-item' style="flex-direction:row;">
<view class='todo-id'>ID</view>
<view class='todo-name'>Task Name</view>
<view class='todo-act'>Done?</view>
</view>
<block wx:for="{{ todoList.items }}" wx:key='item.id'>
<view class='todo-item todo-item-{{item.done}}'>
<view class='todo-id'>{{ item.id }}</view>
<view class='todo-name'>{{ item.name }}</view>
<view class='todo-status'>{{ item.done }}</view>
</view>
</block>
</view>
<view class="usermotto">
<text class="user-motto">{{motto}}</text>
</view>
</view>
/**index.wxss**/
...
.todo-list {
margin-top: 50rpx;
}
.todo-item {
display: flex;
text-align: center;
border-bottom: 1rpx solid gray;
padding: 10rpx 0;
}
.todo-item-N {
color: orange;
}
.todo-item-Y {
color: green;
}
.todo-id {
width: 100rpx;
}
.todo-name {
width: 450rpx;
text-align: left;
}
.todo-status {
width: 100rpx;
}
Register an OAuth Client Application
Configuring Secure Access to RESTful Services
Please notice Bug 27156067 about above only fixed begin with ORDS v3.0.11
By Scott Wan
Demo how to create a Wechat app with Oracle ORDS in 10 minutes.