Skip to content

vasekd/totaljs_restapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MIT License

Total.js RESTAPI visualizer (grey pages)

Create html visualiser for total.js web API. As I call it "grey pages".

restapi screenshot

Installation

  • 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

Usage

Sync response

  • 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'
	});
}

Async response

  • 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

  • start with: npm run dev
  • go to: http://localhost:8080/ ( example api: http://localhost:8080/api/test/ )

License

The source-code is under MIT license.

About

Visualize REST API for total.js framework

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published