0.9.0 • Published 12 years ago

ferryman v0.9.0

Weekly downloads
4
License
-
Repository
github
Last release
12 years ago

Introduction

ferryman is an easy to use routing system written in rails. It supports easy route adding and configuration for GET, POST, PUT, and DELETE.

Usage

Adding a route requires a handle and a function. Although all the example functions take the a request and a response (req and res) as parameters, this is not necessary. The functions will have access to these objects (as req and res) along with any URL parameters.

Handles

All handles should start with a '/'. In order to specify a variable in the pathname, add a '$' and put it in the handle. For instance, if you wanted a variable 'id', the path could be '/$id'. This variable can be accessed directly in the function, though it will be in a string format.

Functions

The route functions by default are run with a scope of null due to how the extra parameters (from the url) are added to the function. In order to allow access to included functions and modules, a more appropriate scope must be added. To do this, you can set fm.CONTEXT. For instance, if you wanted to be able to access the querystring module, it would look like this:

var fm = require('ferryman');
qs = require('querystring');

fm.CONTEXT = global;

fm.put('/page/$id', function(req, res){ 
	var body = qs.parse(req.body); 
	/* Rest of the function. */
};

Examples

This is a basic example of creating routes. A more complete example, including how to route and set the maximum size of PUT and POST data can be found in the example directory.

var fm = require('ferryman');

fm.get('/', function(req, res){ /* Function Body */ });
fm.put('/page/$id', function(req, res){ /* Function Body */ });
fm.post('/page/$id', function(req, res){ /* Function Body */ });
fm.delete('/page/$id', function(req, res){ /* Function Body */ });

License

Copyright (c) 2012, Edward Smith edwardrsmi@gmail.com
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.