How to call remote db?


#1

Hi !
I created a service names “sql”. My problem is that I don’t understand two things.
First : How to connect my new API ?

var dsp_url = "http://localhost/rest/sql";
var app_name = "api";

When I’m trying to loggin, my console tell me : Uncaught TypeError: window.app.login is not a function. I can only loggin with :

var dsp_url = "http://localhost/rest/api_docs";

The second thing is easier : have you got an example of ajax call using jquery to use this API ?


#2

Your dsp_url should always be http://localhost/rest/api_docs, then all functions including window.app.login will be available. The JS SDK readme makes this clear.

If you load the index.html from the JS SDK, you will see described on the page how to access DB records. E.g.,

window.df.apis.db.getRecords({table_name: "todo"}, function (response) {
            console.log(response);
        });

Other available db functions will be displayed if you type window.df.apis in your browser debug console.

Here is an example app in jQuery, and here is a tutorial on how to use it. Also, the DreamFactory REST tester is written in jQuery and may be accessed at http://{YourDreamFactoryURL}/test_rest.html. Finally, here is an Ajax app example for implementing a remote web service call.