1.Call your Jetelina-API through Web Service
I wish you are familiar with the Ajax function, whether it is used on the server or the client, in whatever programming language
i.Case Study in PostgreSQL/MySQL
ii.Case Study in redis
iii.Case Study in MongoDB
i.Case Study in PostgreSQL/MySQL
Case 1:
This is the example for executing ‘insert’ Jetelina-API.
table name: ftest
target columns: ftest_name, ftest_age, ftest_ave
api name: ji9
Under these conditions, the JSON form is expected like this.
IN: {“apino”:”ji9″,”ftest_name”:”Jhon”,”ftest_age”:26,”ftest_ave”:0.86}
behind execution SQL
insert into ftest (ftest_name,ftest_age,ftest_ave) values(‘Jhon’,26,0.86);
OUT: {“result”: true or false, “Jetelina”:”[{}]”, “message from Jetelina”:””…..”}
const getAjaxData = (s) => {
let pd = {};
pd["apino"] = "ji9";
pd["ftest_name"] = "Jhon";
pd["ftest_age"] = 26;
pd["ftest_ave"] = 0.86;
let dd = JSON.stringify(pd);
let url = "http://localhost:8000/apiactions"
$.ajax( {
url: url,
type: "post",
data: dd,
contentType: 'application/json',
dataType: "json",
}).done(function(result, textStatus, jqXHR) {
}).fail( function( result ){
}).always(function(result){
});
}
Case 2:
This is the example for executing ‘select’ Jetelina-API.
table name: ftest
require columns: ftest_jt_id, ftest_name, ftest_age, ftest_ave
api name: js10
Under these conditions, the JSON form is expected like this.
IN: {“apino”:”js10″,”subquery”:”[‘age’:30]”}
behind execution SQL:
select ftest.ftest_jt_id,ftest.ftest_name,ftest.ftest_age,ftest.ftest_ave from ftest as ftest where ftest.ftest_age < 30;
OUT:{“result”:true or false, “Jetelina”:[{“ftest_jt_id”:1,”ftest_name”:”Jhon”,”ftest_age”:26,”ftest_ave”:0.86}],[{…}],”message from Jetelina”:””…..””}
const getAjaxData = (s) => {
let pd = {};
pd["apino"] = "js10";
pd["subquery"] = "['age':30]"; ← attention at here
let dd = JSON.stringify(pd);
let url = "http://localhost:8000/apiactions"
$.ajax( {
url: url,
type: "post",
data: dd,
contentType: 'application/json',
dataType: "json",
}).done(function(result, textStatus, jqXHR) {
}).fail( function( result ){
}).always(function(result){
});
}
Case 3:
This is the example for executing ‘update’ or ‘delete’ Jetelina-API.
table name: ftest
require columns: ftest_jt_id, ftest_name, ftest_age, ftest_ave
api name: ‘ju11’ for ‘update’ or ‘jd12’ for ‘delete’
IN:
for updating:{“apino”:”ju11″,”ftest_name”:”Jhon”,”ftest_age”:26,”ftest_ave”:0.86,”subquery”:46}
behind execution SQL:
update ftest set ftest_name=’Jhon’, ftest_age=26, ftest_ave=0.86 where ftest_jt_id=46;
for deleting:
{“apino”:”jd12″,”subquery”:46}
behind execution SQL:
update ftest set jetelina_delete_flg=1 where ftest_jt_id=46;
OUT: {“result”: true or false, “Jetelina”:”[{}]”, “message from Jetelina”:””…..”}
Both ‘updating’ and ‘deleteing ‘ are the same.
You can see that the ‘delete’ does not perform physical deletion; it simply makes the data inaccessible by setting ‘jetelina_delete_flg’. Jetelina cleans up this hidden data later.
★in case of update Jetelina-API 'ju11'
const getAjaxData = (s) => {
let pd = {};
pd["apino"] = "ju11";
pd["ftest_name"] = "Jhon";
pd["ftest_age"] = 26;
pd["ftest_ave"] = 0.86;
pd["jt_id"] = 46; ← attention at here
let dd = JSON.stringify(pd);
let url = "http://localhost:8000/apiactions"
$.ajax( {
url: url,
type: "post",
data: dd,
contentType: 'application/json',
dataType: "json",
}).done(function(result, textStatus, jqXHR) {
}).fail( function( result ){
}).always(function(result){
});
}
★in case of delete Jetelina-API 'jd12'
const getAjaxData = (s) => {
let pd = {};
pd["apino"] = "jd12";
pd["jt_id"] = 46; ← attention at here
let dd = JSON.stringify(pd);
let url = "http://localhost:8000/apiactions"
$.ajax( {
url: url,
type: "post",
data: dd,
contentType: 'application/json',
dataType: "json",
}).done(function(result, textStatus, jqXHR) {
}).fail( function( result ){
}).always(function(result){
});
}
ii.Case Study in redis
Attention: there is no Jetelina-API for deleting key data.
Case 1:
In case of the ‘insert’ Jetelina-API,
inserting data in redis is inhibited by using Ajax. You can do it only on Jetelina.
Case 2:
The example for executing ‘select’ Jetelina-API.
key name: Jhonsaccesstimes
api name: ‘js20’
Under these conditions, the JSON form is expected like this.
IN: {“apino”:”js20″}
behind execution:
get jhonsaccesstimes
OUT: {“result”: true or false, “Jetelina”:[{“Jhonsaccesstimes”:”32”}],”message from Jetelina”:””…..””}
behind execution:
get jhonsaccesstimes
const getAjaxData = (s) => {
let pd = {};
pd["apino"] = "js20";
let dd = JSON.stringify(pd);
let url = "http://localhost:8000/apiactions"
$.ajax( {
url: url,
type: "post",
data: dd,
contentType: 'application/json',
dataType: "json",
}).done(function(result, textStatus, jqXHR) {
}).fail( function( result ){
}).always(function(result){
});
}
Case 3:
The example for executing ‘update’ Jetelina-API.
key name: Jhonsaccesstimes
value: 100
api name: ‘ju21’
Under these conditions, the JSON form is expected like this.
IN: {“apino”:”ju21″,”key”:”100″}
behind execution:
set jhonsaccesstimes “100”
OUT: {“result”: true or false, “Jetelina”:”[{}]”,” message from Jetelina”:””…..”}
const getAjaxData = (s) => {
let pd = {};
pd["apino"] = "ju20";
pd["Jhonsaccesstimes"] = "100";
let dd = JSON.stringify(pd);
let url = "http://localhost:8000/apiactions"
$.ajax( {
url: url,
type: "post",
data: dd,
contentType: 'application/json',
dataType: "json",
}).done(function(result, textStatus, jqXHR) {
}).fail( function( result ){
}).always(function(result){
});
}
iii.Case Study in MongoDB
Case 1:
This is the example for executing ‘insert’ Jetelina-API.
Document name: newdoc1
api name: ‘ji30’
Under these conditions, the JSON form is expected like this.
IN: {“apino”: “ji30”, “new document”: {“j_table”: “newdoc1”, “name”: “John”, “age”:26, “ave”:0.86}
behind execution:
inserting
OUT: {“result”: true or false, “Jetelina”:”[{}]”, “message from Jetelina”:””…..”}
const getAjaxData = (s) => {
let dd = '{"apino":"ji30","new document":{"j_table":"newdoc1","name":"jhon","age":"26","ave":"0.86"}}';
let url = "http://localhost:8000/apiactions"
$.ajax( {
url: url,
type: "post",
data: dd,
contentType: 'application/json',
dataType: "json",
}).done(function(result, textStatus, jqXHR) {
}).fail( function( result ){
}).always(function(result){
});
}
Case 2:
This is the example for executing ‘select’ or ‘delete’ Jetelina-API.
api name: ‘js31’ for ‘select’ or ‘jd32’ for ‘delete’
Under these conditions, the JSON form is expected like this.
IN:
for selecting: {“apino”:”js31″}
for deletgin :{“apino”: “jd32”}
OUT:
for selecting:
[“{ \”_id\” : { \”$oid\” : \”…..\” }, \”j_table\” : \”newdoc1\”, \”name\” : \”jhon\”, \”age\” : \”26\”, \”ave\” : \”0.86\” }”]
for deleting:
{“result”: true or false, “Jetelina”:”[{}]”,” message from Jetelina”:””….””}
const getAjaxData = (s) => {
let dd = '{"apino":"js31"}';
let url = "http://localhost:8000/apiactions"
$.ajax( {
url: url,
type: "post",
data: dd,
contentType: 'application/json',
dataType: "json",
}).done(function(result, textStatus, jqXHR) {
}).fail( function( result ){
}).always(function(result){
});
}
Case 3:
This is the example for executing ‘update’ Jetelina-API.
api name: ‘ju33’
Under these conditions, the JSON form is expected like this.
IN: {“apino”:”ju33″:”age”:”36″}
behind execution:
updatting teh ‘age’ data
OUT: {“result”: true or false, “Jetelina”:”[{}]”, “message from Jetelina”:””…..”}
const getAjaxData = (s) => {
let dd = '{"apino":"ju33","age":"36"}';
let url = "http://localhost:8000/apiactions"
$.ajax( {
url: url,
type: "post",
data: dd,
contentType: 'application/json',
dataType: "json",
}).done(function(result, textStatus, jqXHR) {
}).fail( function( result ){
}).always(function(result){
});
}
You see every Jetelina-API is thrown against the same URL, ‘http://localhost:8000/apiactions’, no matter what database. This is the only one post gate way for your web service. And this post URL has alternative names: ‘plzjetelina’ and ‘executionapi’, which work in the same way as ‘apiactions’.
2. Test page in HTML for your Jetelina-API
Jetelina has a Jetelina-API test page. This page is for testing your Jetelina-API by using similar program is introduted above. You can access to this page on your site ‘….jetelina/jetelina_apitest.html’. e.g http://localhost:8000/jetelina/jetelina_apitest.html.
