I am working on a large scale JavaScript application using BoilerplateJS. In the viewmodel I want to connect to an external REST API which will return JSON objects. But I am not sure about how to implement this. Can someone give me an idea. Thanks in advance.
Asked
Active
Viewed 196 times
1 Answers
1
most of the sample UI components there access the server for JSON requests. For example have a look at "src/modules/sampleModule1/departments/viewmodel.js". Under 'initialize' method you will see:
$.getJSON(moduleContext.getSettings().urls.departments, function(result) {
self.allItems(result);
});
Here "moduleContext.getSettings().urls.departments" is the URL to the server script that returns the JSON. The other parameter is the callback function to handle the JSON response. In the samples, there is no server scripts, so we mimic the server scripts with simple JSON files stored under 'server' folder. For example in this case the request is for "/server/departments.txt"

Hasith
- 1,749
- 20
- 26