A functional approach to REST api's.
A digger supplier is just a function - it accepts req and reply arguments.
// a request represent a load of item 1234method:'get'url:'/1234'headers:body:null
reply is a standard node.js callback.
$ npm install digger-supplier --save
A supplier has 4 distinct roles to play.
These are conceptually mapped onto the REST methods: GET, POST, PUT, DELETE
A supplier is a digger-warehouse - which means you can mount middleware onto a supplier like any other warehouse.
var Supplier = ;var supplier = ;// mount a custom middleware onto the supplier// this is called before the database methodssupplier
The point of a supplier is to connect to a data source on the back and interpret our container queries upon that data.
It is useful to have the same supplier object deal with different backend resources (like files or databases) based upon the route that is used.
Imagine we have a supplier mounted on '/csv' - it is a csv file supplier that has access to a directory '/tmp/mycsvsupplier'.
var folder = '/tmp/mycsvsupplier';var Supplier = ;// we create the supplier with an factory functionvar supplier =// we run the provision function for every request - it decides what specific database table/collection/file to use// based upon the route//// it is basically a renamed .usesupplier
You specify what happens in your supplier when a container is:
var Supplier = ;var supplier = ;/*search the database with a selector and context array*/supplier/*add an item to the database*/suppliersuppliersupplier