ResSendr - Friendly request handlers.

github.com/scup/ResSendr

Getting Started

Installing

        
$ npm install ressendr --save
        
        

Before :

        
app.get('/hello',requestHandler)

function requestHandler(req, res){
  res.end('World!')
}
        
        

After :

        
import r from 'ressendr'

app.get('/hello',r.handle(requestHandler))

function requestHandler(req){
  return 'World!';
}
        
        

Using with promises:

Before :


app.get('/hello',requestHandler)

function requestHandler(req, res){
  asyncIO.get()
  .then((response)=>{
    res.end(response);
  })
}

After :


import r from 'ressendr'

app.get('/hello',r.handle(requestHandler))

function requestHandler(req, res){
  return asyncIO.get()
}

Writing yout own handlers :


import r from 'ressendr'


//First we need a function that returns true or false
//true if the data can be handlered by the handle.
//so lets write a number Handler

let isNumber = value => !isNaN(value);

//Now we need to handle the value and send it.

let handler = (v,res) => res.end(v.toString());

r.addHandler(isNumber,handler);

app.get('/hello',r.handle(requestHandler))

function requestHandler(req, res){
  return 2
}