Comparing version 0.2.0 to 0.2.1
16
index.js
@@ -37,3 +37,3 @@ // Dependencies | ||
if (options.restrict) options.restrict(query); | ||
if (options.restrict) options.restrict(query, request); | ||
@@ -56,3 +56,3 @@ query.count(function (error, count) { | ||
if (options.restrict) options.restrict(query); | ||
if (options.restrict) options.restrict(query, request); | ||
@@ -89,3 +89,3 @@ query.exec(function (error, doc) { | ||
if (options.restrict) options.restrict(query); | ||
if (options.restrict) options.restrict(query, request); | ||
@@ -111,3 +111,3 @@ query.exec(function (error, doc) { | ||
if (options.restrict) options.restrict(query); | ||
if (options.restrict) options.restrict(query, request); | ||
@@ -135,3 +135,3 @@ query.exec(function (error, count) { | ||
if (options.restrict) options.restrict(query); | ||
if (options.restrict) options.restrict(query, request); | ||
@@ -159,3 +159,3 @@ query.count(function (error, count) { | ||
if (options.restrict) options.restrict(query); | ||
if (options.restrict) options.restrict(query, request); | ||
@@ -194,3 +194,3 @@ query.exec(function (error, docs) { | ||
if (options.restrict) options.restrict(query); | ||
if (options.restrict) options.restrict(query, request); | ||
@@ -229,3 +229,3 @@ query.exec(function (error, doc) { | ||
if (options.restrict) options.restrict(query); | ||
if (options.restrict) options.restrict(query, request); | ||
@@ -232,0 +232,0 @@ query.exec(function (error, count) { |
{ | ||
"name": "baucis", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -1,2 +0,2 @@ | ||
baucis v0.2.0 | ||
baucis v0.2.1 | ||
============= | ||
@@ -16,8 +16,6 @@ | ||
An example of creating a REST API: | ||
An example of creating a REST API from a Mongoose schema: | ||
var baucis = require('baucis'); | ||
// Define a Mongoose schema | ||
var Vegetable = new Schema({ | ||
var Vegetable = new mongoose.Schema({ | ||
name: String | ||
@@ -36,3 +34,3 @@ }); | ||
Later make requests: | ||
Later, make requests: | ||
@@ -48,6 +46,4 @@ * GET /api/v1/vegetables/:id — get the addressed document | ||
Baucis supports embedding controllers in other controllers, as well as embedding arbitrary routes and middleware. | ||
`baucis.rest` returns an instance of the controller created to handle the schema's routes. | ||
var baucis = require('baucis'); | ||
var controller = baucis.rest({ | ||
@@ -60,4 +56,4 @@ singular: 'foo' | ||
publish: false, // don't add routes automatically | ||
restrict: function (query) { | ||
query.where({ ticket: request.param('ticket') }); | ||
restrict: function (query, request) { // allows direct access to the Mongoose queries | ||
query.where({ parent: request.params.fooId }); | ||
} | ||
@@ -69,3 +65,3 @@ }); | ||
// Embed arbitrary middleware | ||
// Embed arbitrary middleware at /foos/:fooId/qux | ||
controller.use('/:fooId/qux', function (request, response, next) { | ||
@@ -82,3 +78,3 @@ // Do something cool… | ||
controller.use(express.cookieParser()); | ||
controller.use(function () { ... }); | ||
controller.set('some option name', 'value'); | ||
@@ -106,19 +102,15 @@ controller.listen(3000); | ||
An example `sync` method for a Backbone model: | ||
An example with Backbone: | ||
function (method, model, options) { | ||
var url = '/api/v1/vegetables'; | ||
var Foos = Backbone.Collection.extend({ | ||
url: '/foos' | ||
}); | ||
if (method !== 'create') url += model.id; | ||
var Bar = Backbone.Model.extend({ | ||
urlRoot: '/bars' | ||
}); | ||
options = options || {}; | ||
options.url = url; | ||
Use plain old Connect/Express middleware, including pre-existing modules like `passport`. For example, set the `all` option to add middleware to be called before all the model's API routes. | ||
return Backbone.sync(method, model, options); | ||
} | ||
Use middleware for security, etc. Middleware is plain old Connect middleware, so it can be used with pre-existing modules like `passport`. For example, set the `all` option to add middleware to be called before all the model's API routes. | ||
baucis.rest({ | ||
schema: Vegetable, | ||
singular: 'vegetable', | ||
@@ -131,3 +123,13 @@ all: function (request, response, next) { | ||
Or, set some middleware for specific HTTP verbs: | ||
baucis.rest({ | ||
singular: 'vegetable', | ||
get: [middleware1, middleware2], | ||
post: middleware3, | ||
del: [middleware4, middleware5] | ||
}); | ||
Contact Info | ||
------------ | ||
@@ -134,0 +136,0 @@ * http://kun.io/ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
227158
132