hapi-datify

your datify-friendly hapi plugin.

npm install hapi-datify
3 downloads in the last week
12 downloads in the last month

hapi-datify

your datify-friendly hapi plugin.

Build Status

how

> npm install hapi-datify

use hapi-datify as a plugin for hapi. For example, if you use hapi cli tool (or composer), put it in your config file:

{
  "servers": [
    {
      "host": "localhost",
      "port": 8000,
      "options": {
        "labels": ["api", "nasty"]
      }
    }
  ],
  "plugins": {
    "hapi-datify": {
      "routesToDatifyRegEx": "^/books&"
    }
  }
}

The example above will datify only the /books route, meaning, it will datify request.payload, request.query .

why

see datify#why.

For example, you could:

pack.route({ method: 'POST', path: '/books', handler: function(request){
            // store the book in the DB with a real js Date - that means you can query using dates later on
            //  POST /books --data {"publishedAt": "2012-09-13T17:09:30.909Z", ...}
              books.insert(request.payload, function(err, documents){ 
                request.reply("ok\n");
              });
            } 
          });
pack.route({ method: 'GET', path: '/books', handler: function(request){
            // find a book published from a date, without having to parse dates
            // GET /books?from=2011-09-13T17:09:30.909Z
              books.find({ publishedAt: { $gte: request.query.from } }, function(err, books){ 
                request.reply({results: books});
              });
            } 
          });

test

> npm install
> make test-cov

NPM

npm loves you