Method calls in $http are asynchronous: The result will not be necessarily available after the function .get() returns. Please check again the docs for $http.
Data in webresponse will not be available (i.e. your variable is not set yet to anything other than the plain object) but only when the $http.get request fetches the data from the server. Such moments are the .success trigger, the .error trigger, and also a trigger you did not use (and perhaps don't need) called .finally (works regardless whether .success and .error have been triggered).
You cannot access the webresponse outside those callbacks since they are the only guaranteed moments where such values will be available. Even more! You cannot RETURN such value from the function. Since the behavior is asynchronous you will have to return something in the same asynchronous way. Please check the $q service to learn how to do it. It is a long topic and you lack the basics on this topic so I will give you some guidelines:
$http is an asynchronous service. Their calls (e.g. .get() return something called a promise. Your function should return a promise (either the same or other).
- The actual result itself (i.e. the result you want) will not be available as you intend: The function's invoker must attend the promise you return, specify a callback for it, and attend it in the callback.
- More information: You need a deeper knowledge of
$http and $q services. They are pretty well documented in the official docs.