In Angular 4 or any client-side framework other than WAF. the JSON-PRC service can be accessed as an external module in your app using HTTP POST.
According to the docs, If you want to call a Wakanda RPC method from any external Page, you need to add a "script" tag to the HTML page. For example:
<script type="text/javascript" src="/rpc-proxy/myRPC?namespace=myRPC"></script>
WAF
and myRPC
will become available in your angular app.
Then all you have to do is to consume the namespace myRPC (with a couple tweaks).
Here is what I have done to get it work:
Add the script in index.html
Then, declare WAF and myRPC in your app.component.ts:
declare var myRPC: any;
declare var WAF: any;
Make the tweak to WAF object:
WAF.core = {restConnect:{baseURL : "${window.location.origin}"}};
WAF.config = {enableFilePackage:true}
Call myRPC using documented API:
myRPC.isEmptyAsync({
'onSuccess': function(result) {
console.log(result);
},
'onError': function(error){
console.log('An error occured: '+error);
},
'params': [4, 5]})
update "proxy.conf.json": with following JSON object:
{
"/rest/*": {
"target": "http://127.0.0.1:8081",
"secure": false,
"ws": true,
"headers": {
"host": "127.0.0.1:8081",
"origin": "http://127.0.0.1:8081"
}
},
"/rpc-proxy/*": {
"target": "http://127.0.0.1:8081",
"secure": false,
"ws": true,
"headers": {
"host": "127.0.0.1:8081",
"origin": "http://127.0.0.1:8081"
}
},
"/rpc/*": {
"target": "http://127.0.0.1:8081",
"secure": false,
"ws": true,
"headers": {
"host": "127.0.0.1:8081",
"origin": "http://127.0.0.1:8081"
}
}
}
Hope this helps.