1

To bind my data on the mobile side it works like this :

getHeros() {
    this.wakanda.getCatalog().then(ds => {
        ds['Superhero'].query({orderBy:"ID desc",pageSize:3}).then(collection => {
            this.favoriteSuperheroes = collection.entities;
        });
    });
}

But like this I work directly on the table. I have a method who provide me everything I want on the server side.

I want to know, if I call my method in the backend and store it in a variable like this:

var favoriteMethod = ds.Superhero.myDataClassMethod();

How I can use this variable on the mobile side ?

CoCoNours
  • 233
  • 1
  • 2
  • 13

1 Answers1

2

Your first example is probably the best. Another (longer) trick would be to:

  • Create a request handler

    // Let's say you define a http://127.0.0.1:8081/getSuperHeroesData request handler httpServer.addRequestHandler('^/getSuperHeroesData$', 'super-heroes-module', 'getData');

  • Define a super-heroes-module module in your backend/modules directory

    // modules/super-heroes-module/index.js exports.getData = function pong( request, response ){ return ds.Superhero.myDataClassMethod(); }

  • So when you call http://127.0.0.1:8081/getSuperHeroesData from your mobile front end, it will trigger the getData method from super-heroes-module and return the result in your HTTP request response.

Wakanda request handler documentation

Yann
  • 478
  • 5
  • 10
  • sorry to disturb you, but I don't understand how it work. How I can send back the result to the mobile side ? – CoCoNours Apr 24 '17 at 14:58
  • @CoCoNours I update my response with more details. Hope it helps. :) – Yann Apr 24 '17 at 15:17
  • Thanks for your reply. I try to figure out how handler request works. I create a request handler and define a module, but how I can call it from the mobile side ? How can I give arguments to my method, with handle request ? – CoCoNours Apr 25 '17 at 09:42
  • What I try to do is for exemple: When I push a button I call my method and give an argument in terms of the button. My method return what I want, and I want to receive this in the mobile side to display it. Is it possible with request handler ? – CoCoNours Apr 25 '17 at 09:46
  • First, start by create/test your http request in Wakanda. All parameters of your request are available in your `getData` method with the `request` parameter. Use your browser to test it. This is basic HTTP stuff. Second step, plug you front end (mobile) on this request handler. Once again, this is basic angular / ionic stuff and there is plenty of thread on stackoverflow and internet about it. https://www.thepolyglotdeveloper.com/2014/08/make-http-requests-android-ios-ionicframework/ https://docs.angularjs.org/api/ng/service/$http – Yann Apr 25 '17 at 12:21
  • Tanks for your reply and your patience. The first step is ok I can test it on the browser and my method return what I want. But for the second step I try this line on the mobile side : "this.http.get("http://127.0.0.1:8081/getCompanyData").subscribe(data => { console.log(data); });" But I have this following error : "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8114' is therefore not allowed access." Do I need to pass by cross-domain request ? – CoCoNours Apr 26 '17 at 13:40
  • This is a CORS error. You can to enable CORS in your Wakanda project settings. Accept connection from `127.0.0.1:8114`. – Yann Apr 26 '17 at 14:36