Consume DSP json results from DF in AngularJs

Good evening, sorry for my dummy question, i’m a newbie on DF stack.
I tried to consume Json results from my local XAMP mounted DSP, aimed to a MySql local istance. Json stream is produced , no authentication problems,etc but if i use json coming from such dsp, these outcomes are not “recognized” by AngularJs

Here is an example ( my html page output ) :

Item List
[{“id”:1,“name”:“Fabrissios”,“email”:“fabrissio@provider.it”,“mobile”:“323232323”},{“id”:2,“name”:“alessios”,“email”:“alessio@provider.it”,“mobile”:“39i4394394398”}]

If i use the same javascript on a sample restful server i get a kind of json results i can immediately use in my AngularJs app

http://jsonplaceholder.typicode.com/users

and this is my very simple angularJs code for controller:

app.controller(
	'MainCtrl', 
	function($scope,$http) {
 		//var promise = $http.get('http://jsonplaceholder.typicode.com/users');
 		var promise = $http.get('http://localhost:80/rest/mysqllocal_phptutorial/customers?app_name=DF_EXPLORE');
 	
 		promise.then (
 			function(response) {
				$scope.options = response.data;
 		})

I know it’s not an AngularJs forum but it sounds strange to me not being able to consume dsp json response like any other json response i got around the web for testing purposes

I know maybe i’m missing some details on DSP admin or something like that , please, kindly help these poor newbie

Thanks guys, my best regards
Fabrizio

Hi @JDream, can you confirm that you enabled guest access and provided GET access to the guest role for your mysqllocal_phptutorial service? Because otherwise you will need to authenticate.

What response or error is returned to your call as it is now? E.g., what’s the response to the same call ( GET http://localhost:80/rest/mysqllocal_phptutorial/customers?app_name=DF_EXPLORE ) from a browser or cURL?

Hi i get no error at all!

The snippet i posted was exactly the html output i got with a DSP call

Item List
[{“id”:1,“name”:“Fabrissios”,“email”:“fabrissio@provider.it”,“mobile”:“323232323”},{“id”:2,“name”:“alessios”,“email”:“alessio@provider.it”,“mobile”:“39i4394394398”}]

if i run the same script on

http://jsonplaceholder.typicode.com/users

the ng-repeat directive can address correctly any attribute of Json , if i use DSP json stream, i can’t

Just the Json format seems to be not recognized by AngularJs, This sound strange to me.
It seems, at first sight, that i can’t consume DSP json streams natively via Angular but some operations must be performed in turn to get this job done.

It’s strange because other online restful services are immediately usable via Angular with the same ,exact, script i posted ( as the above mentioned http://jsonplaceholder.typicode.com/users )

That’s why i was asking and wondering! If i cand find a way, DF can be presented like a standard way of getting a restful backend on any data provider!

Thank you for your time and patience
Fabrizio

What response or error is returned to your call as it is now? E.g., what’s the response to the same call ( GET http://localhost:80/rest/mysqllocal_phptutorial/customers?app_name=DF_EXPLORE ) from a browser or cURL?

Hi, i don’t get any error since i’ve activated guest access and a role “Download” ( like stated in community tutorial ) that allows me to do almost anything

The problem is due to json stream format i get as a reponse : AngularJS is not able to treat it like other json stream that i can get over the web.

I think a trick is needed to consume DSP json stream, maybe i’m “forced” to use the javascript APK , i thought it was possible to use standard angular scope assignment method

Thank you for any further reply
Fabrizio

What response is returned to your call as it is now? What’s the response to the same call ( GET http://localhost:80/rest/mysqllocal_phptutorial/customers?app_name=DF_EXPLORE ) from a browser or cURL?

Hi Jeffrey, i get no error.

The concern was about the json wrapper “RECORD:” which doesn’t make json stream data immediately usable.

You just need to reference “responsedata.record” but i wished to know why, usually rest service do not wrap the stream.

The idea behind this is DF metadata layer, now it’s clear.

Thank you and best regards
Fabrizio

Thanks for coming back with the explanation, @JDream. I was hoping to see your raw response in cURL or a browser and point out just that fact, that the response is wrapped in record:

Response

{
  "record": [
    {
      "id": 1,
      "name": "Check out DF REST API",
      "complete": true
    }
  ]
}

The above example is taken from Database Retrieving Records in the DreamFactory documentation.