hapi-datify

your datify-friendly hapi plugin.

hapi-datify

your datify-friendly hapi plugin.

> 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 .

see datify#why.

For example, you could:

pack.route({ method: 'POST', path: '/books', handlerfunction(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(errdocuments){ 
                request.reply("ok\n");
              });
            } 
          });
pack.route({ method: 'GET', path: '/books', handlerfunction(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(errbooks){ 
                request.reply({results: books});
              });
            } 
          });
> npm install
> make test-cov