Create html visualiser for total.js web API. As I call it "grey pages".
cd <your totaljs project>
- create bundles directory
mkdir bundles
- create bundle config
echo https://github.com/vasekd/totaljs_restapi/raw/master/restapi.bundle > ./bundles/restapi.url
- create dir:
mdkir controllers
- create router in controllers/api.js:
exports.install = function() {
// Sets cors for this all API
CORS('/api/*', ['get'], true);
// Routes
ROUTE('/api/test', item_query);
};
function item_query() {
this.result(200, {
data: 'test struct'
});
}
- create dir:
mdkir controllers
- save this to the file controllers/api.js:
- make sure you have define *Item model ex:
NEWSCHEMA('Item').make(function(schema) {
schema.define('id', 'UID');
schema.define('date', 'Date', true);
schema.define('pay', 'String', true);
schema.define('present', 'Object', true);
schema.setGet(function($) {
var item = NOSQL('item');
// Reads
item.one().make(function(builder) {
builder.where('id', $.options.id);
builder.callback($.callback, 'error-item-404');
});
});
});
- create router in controllers/api.js:
exports.install = function() {
// Sets cors for this all API
CORS('/api/*', ['get'], true);
// Routes
ROUTE('/api/test', item_query, ['*Item']);
};
function item_query() {
var self = this;
var options = {};
options.search = self.query.search;
self.$query(options, self.resultCallback());
}
- start with:
npm run dev
- go to:
http://localhost:8080/
( example api:http://localhost:8080/api/test/
)
The source-code is under MIT license.