Nayk0
Nayk0

Reputation: 101

Wakanda RPC client side

I created a JS file inside the modules folder (backend) in Wakanda Studio (Angular 4 project), I enabled RPC and added it to permissions.waPerm file.

When I check in localhost:8081/rpc-proxy/myRpc/ I can see that the method exists but I don't know how to access it client side since every documentation about it talk about using the Prototyper or GUI Designer of Wakanda studio, but these two doesn't exist anymore in the current version of the studio.

Any idea ?

Upvotes: 1

Views: 262

Answers (1)

Xiang Liu
Xiang Liu

Reputation: 393

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:

  1. Add the script in index.html

  2. Then, declare WAF and myRPC in your app.component.ts:

    declare var myRPC: any; declare var WAF: any;

  3. Make the tweak to WAF object:

    WAF.core = {restConnect:{baseURL : "${window.location.origin}"}}; WAF.config = {enableFilePackage:true}

  4. 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]})

  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.

Upvotes: 1

Related Questions