cuter-controllers

0.0.5 • Public • Published

cuter-controllers

A quick and simple way to build routers in JavaScript.

Introduction

There's way too many tiny frameworks with help your build controllers in JavaScript. On another hand, theres a whole bunch of frameworks which aslo have fantastic fouter support. Which is awesome.

I created cuter-controllers to be the framework which may be just another Javascript framework just because. I usually use it with mde/model, but there's literally no reason for that to be necessary.

Requirements

  • Node >0.11.x

Quick Start

npm install --save cuter-controllers

Make a controller. Here's a sample using the REST controller trait (functions are JavaScript generators and either return or throw data. req is an express request object):

module.exports = {
    get_index: function * (req) {
        console.log('In real life, putting echos in a controller is probably a bad idea.');
        return;
    },
    get_demo: function * (req) {
        return {
            'my_name': 'tylermenezes'
        };
    },
    get_error: function * (req) {
        throw 'good error!';
    },
    get_response: function * (req) {
        var res = new Response(418).headers({
            "Content-Type": "text/html"
        }).body('<b>Hello world!</b>');
        return res;
    }
}

Save it to [/path/to/your/project]/controllers/<controllername>.js

Start the router! In your index file, run:

require('cuter-controllers').start('./controllers');

Then run with the --harmony tag:

node --harmony server.js

Visit it on the web! Here's a list of URLs which should work:

  • /test
  • /test/index
  • /test/demo
  • /test/response

Controllers

pbbbbbbbbbbbt. i hate documentation.

Readme

Keywords

none

Package Sidebar

Install

npm i cuter-controllers

Weekly Downloads

0

Version

0.0.5

License

none

Last publish

Collaborators

  • tangmi