Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Latest commit

 

History

History
64 lines (53 loc) · 1.82 KB

README.md

File metadata and controls

64 lines (53 loc) · 1.82 KB

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