1.0.0 • Published 10 years ago

folio.js v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

folio.js

npm version Build Status Dependency Status devDependency Status Code Climate

A fluent Node.js HTTP API framework inspired by express

Install

The best way to add folio.js to your project is to use npm.

npm install folio.js --save

Basic Example

// Require folio.js
var Folio = require('folio.js');

// Create a new folio.js application
var myApp = new Folio();

/*
 * Define a route for GET /hello-world/:variableA/with/:variableB where
 * :variableA and :variableB are variable components. The route is to use
 * three middleware and should use the given handler.
 */
myApp.get('/hello-world/:variableA/with/:variableB')
	.middleware(myMiddlewareA, myMiddlewareB, myMiddlewareC)
	.handler(myHelloWorldHandler);

/*
 * Define a route for POST /hello-world with no route specific middleware,
 * but given a handler.
 */
myApp.post('/hello-world').handler(myPostHandler);

// Specify a set of middleware to use for all routes.
myApp.use(myGlobalMiddlewareA, myGlobalMiddlewareB).forAllRoutes();

// Specify a set of middleware to use for GET routes.
myApp.use(myGlobalPostMiddleware).forAllPosts();

// Start the server, and have it listen for requests on port 3000.
myapp.start(3000);

Middleware Functions

var exampleMiddleware = function(request, response, next) {
	
	/* 
	 * Do what the middleware needs to do, then call next() if the
	 * handling chain should be continued - otherwise terminate
	 * the response.
	 */

	if(authorised(request)) {
		// Continue with handling chain.
		next();
	} else {
		// Terminate response.
		response.statusCode = 401;
		response.end();
	}
};

Handler Functions

var exampleHandler = function(request, response) {
	
	var variableA = request.params['variableA'];
	var variableB = request.params['variableB'];

	myDatabase.findMyObject(variableA, variableB, function(result){
	    response.send(result);
	});
};

License

Folio is licensed under the MIT license.

1.0.0

10 years ago

0.0.3

10 years ago

0.0.2

11 years ago

0.0.1

11 years ago