How to get data from makeWebRequest

Hello! I'm new to monkey C and I'm trying to develop a program which gets json data from internet. I'm currently following that first example of page:

https://developer.garmin.com/connect-iq/core-topics/https/

I'm in that point, that I am able to call makeRequest function from my "main" function and print data to debug console from that onReceive function. But how can I return that fetched data from makeRequest function so I could handle that data in my "main" function? Maybe should use that responseCallback variable which is some kind of Method?

  • *a few moments later pic here*

    After lot of researching I found solution from github example, I will link it down below if some else is learning and stuck here.

    github.com/.../GarminWebRequestTest

  • data is a local variable to the onRecieve call back, and all you have to do is copy it to a class variable and then it's available to anything in that class

    class MyView extends WatchUi.View {
        var Mydata=null;
        
        ... (other stuff)
        
        function onUpdate(dc) {
            //if Mydata isn't null, use it
        }
        
        function onReceive(responseCode, data) {
            if(responseCode==200) {
                Mydata=data;
            }
        }
    }