From the Izyware Dashboard, pick a content distribution app template and to generate your new app.
If a URI scheme has already been created, skip to the next step.
Create a URI scheme for the component that would make the content availble. Izyware Cloud Platform will aggregate and integrate the URI scheme in a larger hierarchy if needed (i.e. when you embed your app inside another), so you dont need to worry about future extensibility.
The definition of the URI matches is entirly up to the creator, but it is recommended that you always implement offset and limit when working with large datas sets:
modtask.calcNav = function(cb) {
var items = [{path: 'catalog/./offset/./limit/.*',
pattern: {// will come out as itemid property in ['framegetkey', '_matches', modtask]
matches: ['textsearch', 'offset', 'limit']},
views: {body: modtask.ldmod('kernel/path').rel('catalog/frame')
}}];
cb(items);}
So now you can create catalog/frame
. The first step is to validate the current URI and if valid, create the validationState
. In case any parameters are invalid, you can indicate that by create a non-200 status.
modtask.calcValidateState = function(cb) {
modtask.matches = modtask.matches || {};modtask.params = modtask.params || {};
var currentUrlMatchedAgainst = modtask.params.currentUrlMatchedAgainst || ''; modtask.matchesProps = {'textsearch': '',
'offset': 0,'limit': 8
}; modtask.validationState = {status: 200,
data: {}};
var p;for (p in modtask.matchesProps) {
var deserialized = decodeURIComponent(modtask.matches[p] || modtask.matchesProps[p]);modtask.validationState.data[p] = deserialized;
}return cb(modtask.validationState);
}Do not try to load the content in this stage. If you would like to generate a 404 status for empty content, this can be accomplished in the calcPulses stage.
The app can now use the validationState.data parameters (offset, limist, etc.) to generate the pulse data set:
modtask.calcPulses = function(cb) {
var uriMatches = modtask.validationState.data;var fieldmap = {
// first two are mandatory'id': 'id',
'address': 'address','title' : 'title',
'description': 'description'};
var fields = Object.keys(fieldmap);return cb({
content: {sql: 'select ' + fields.join(',') + ' from mydatasource where 1 = 1 ' + ' LIMIT ' + uriMatches.offset + ', ' + uriMatches.limit,
fields: fields,fieldmap: fieldmap
}});
}After publishing it, the app can be accessed either as a standalone end-point or integrated into an existing workflow or even an api end-point.
You can now navigate
your data source easily by just adjusting the URL matches in your browser address bar:
catalog//offset/0/limit/2
In the next installment of the series, we will discuss adding discovery links to the app.