Comparing version 0.3.0-2 to 0.3.1-1
14
index.js
@@ -332,2 +332,12 @@ // Dependencies | ||
// Build the "Accept" response header | ||
function addAcceptResponseHeader (options) { | ||
var f = function (request, response, next) { | ||
response.set('Accept', 'application/json'); | ||
next(); | ||
}; | ||
return f; | ||
} | ||
// Validation | ||
@@ -379,6 +389,8 @@ // ---------- | ||
controller.use(express.bodyParser()); | ||
controller.use(express.json()); | ||
controller.all(basePathWithId, addAllowResponseHeader(options)); | ||
controller.all(basePathWithId, addAcceptResponseHeader(options)); | ||
controller.all(basePath, addAllowResponseHeader(options)); | ||
controller.all(basePath, addAcceptResponseHeader(options)); | ||
@@ -385,0 +397,0 @@ if (options.configure) options.configure(controller); |
{ | ||
"name": "baucis", | ||
"version": "0.3.0-2", | ||
"version": "0.3.1-1", | ||
"main": "index.js", | ||
@@ -14,3 +14,3 @@ "scripts": { | ||
"description": "Module for automatically creating REST interfaces for mongoose schemata", | ||
"keywords": [ "REST", "API", "mongoose", "schema", "schemata", "mongo", "automatic" ], | ||
"keywords": [ "REST", "API", "express", "mongoose", "schema", "schemata", "mongo" ], | ||
"devDependencies": { | ||
@@ -17,0 +17,0 @@ "mocha": "~1.8.2" |
@@ -1,15 +0,13 @@ | ||
baucis v0.3.0-2 | ||
baucis v0.3.1-1 | ||
=============== | ||
*** WORK IN PROGRESS *** | ||
Baucis is Express middleware used to build REST services based on Mongoose schemata. | ||
Baucis is Express middleware for automatically creating REST services from Mongoose schemata. | ||
Like Baucis and Philemon of old, this library provides REST to the weary traveler. The goal is to create a JSON REST API for Mongoose & Express that matches as closely as possible the richness and versatility of the [HTTP 1.1 protocol](http://www.w3.org/Protocols/rfc2616/rfc2616.html). | ||
Like Baucis and Philemon of old, this library provides REST to the weary traveler. The goal is to create a JSON REST API for Mongoose that matches as closely as possible the richness and versatility of the [HTTP 1.1 protocol](http://www.w3.org/Protocols/rfc2616/rfc2616.html). | ||
Those versions published to npm represent release versions. Those versions not published to npm are development releases. | ||
Relase versions of baucis can be considered stable. (Please report issues on GitHub if bugs are encountered.) | ||
Relase versions of baucis can be considered stable. Baucis uses [semver](http://semver.org). | ||
The API is subject to change. (Baucis uses semver.) | ||
Please report issues on GitHub if bugs are encountered. | ||
@@ -139,12 +137,7 @@ ![David Rjckaert III - Philemon and Baucis Giving Hospitality to Jupiter and Mercury](http://github.com/wprl/baucis/raw/master/david_rijckaert_iii-philemon_and_baucis.jpg "Hermes is like: 'Hey Baucis, don't kill that goose. And thanks for the REST.'") | ||
url: '/api/v1/vegetables', | ||
data: { name: 'Potato' } | ||
}).done(function (vegetable) { | ||
console.dir(vegetable); | ||
}); | ||
$.ajax({ | ||
type: 'GET', | ||
dataType: 'json', | ||
url: '/api/v1/vegetables', | ||
data: { query: JSON.stringify({ color: 'red' }) } | ||
data: { | ||
conditions: JSON.stringify({ | ||
name: 'Potato' | ||
}) | ||
} | ||
}).done(function (vegetables) { | ||
@@ -158,4 +151,15 @@ console.dir(vegetables); | ||
url: '/vegetables', | ||
baucis: function (query) { | ||
return this.fetch({ data: { query: JSON.stringify(query) } }); | ||
// This method JSONifies baucis' options into fetch's `data` option, | ||
// while leaving regular fetch options as they are. | ||
baucis: function (baucisOptions, fetchOptions) { | ||
fetchOptions = _.clone(fetchOptions || {}); | ||
fetchOptions.data = {}; | ||
if (baucisOptions) { | ||
Object.keys(baucisOptions).forEach(function (key) { | ||
fetchOptions.data[key] = JSON.stringify(baucisOptions[key]) | ||
}); | ||
} | ||
return this.fetch(fetchOptions); | ||
} | ||
@@ -168,5 +172,31 @@ }); | ||
var redVeges = new Vegetables(); | ||
redVeges.baucis({ color: 'red' }).then(function () { ... }); | ||
var vegetables = new Vegetables(); | ||
vegetables.baucis({ conditions: { color: 'red' } }).then( ... ); | ||
// Besides, the `conditions` option, `populate` is also currently | ||
// supported, to allow population of references to other documents. | ||
var promise = vegetables.baucis({ | ||
conditions: { color: red, 'nutirition.soudium': { $lte: 10 } }, | ||
populate: 'child' | ||
}}); | ||
// or | ||
populate: ['child1i', 'child2' ] | ||
// or | ||
populate: [{ | ||
path: 'child1', | ||
select: ['fieldA', 'fieldB'], | ||
match: { | ||
'foo': { $gte: 7 } | ||
}, | ||
options: { limit: 1 } | ||
}, ... ] | ||
See the Mongoose [population documentation](http://mongoosejs.com/docs/populate.html) for more information! | ||
Contact Info | ||
@@ -173,0 +203,0 @@ ------------ |
235095
984
206