Comparing version 0.3.1 to 0.3.2
@@ -378,6 +378,8 @@ // Dependencies | ||
baucis.rest = function (options) { | ||
options || (options = {}); // TODO clone | ||
options || (options = {}); // TODO clone, defaults | ||
if (!options.singular) throw new Error('Must provide the Mongoose schema name'); | ||
if (!options.plural) options.plural = lingo.en.pluralize(options.singular); | ||
if (!options.basePath) options.basePath = '/'; | ||
@@ -384,0 +386,0 @@ var basePath = options.basePath = path.join('/', options.basePath); |
{ | ||
"name": "baucis", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"main": "index.js", | ||
@@ -13,4 +13,4 @@ "scripts": { | ||
"license": "MIT", | ||
"description": "Module for automatically creating REST interfaces for mongoose schemata", | ||
"keywords": [ "REST", "API", "mongoose", "schema", "schemata", "mongo", "automatic" ], | ||
"description": "Baucis is Express middleware that creates configurable REST APIs using Mongoose schemata.", | ||
"keywords": [ "REST", "API", "express", "mongoose", "schema", "schemata", "mongo" ], | ||
"devDependencies": { | ||
@@ -17,0 +17,0 @@ "mocha": "~1.8.2" |
170
README.md
@@ -1,15 +0,13 @@ | ||
baucis v0.3.1 | ||
baucis v0.3.2 | ||
============= | ||
*** WORK IN PROGRESS *** | ||
Baucis is Express middleware that creates configurable REST APIs using 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. | ||
@@ -57,2 +55,99 @@ ![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.'") | ||
Also note that Mongoose middleware will be executed as usual. | ||
Vegetable.pre('save', function () { ... }); | ||
Examples | ||
-------- | ||
Examples with jQuery: | ||
$.getJSON('/api/v1/vegetables/4f4028e6e5139bf4e472cca1', function (data) { | ||
console.log(data); | ||
}); | ||
$.ajax({ | ||
type: 'POST', | ||
dataType: 'json', | ||
url: '/api/v1/vegetables', | ||
data: { | ||
name: 'carrot', | ||
color: 'orange' | ||
} | ||
}).done(function (vegetable) { | ||
// The new document that was just created | ||
console.dir(vegetable); | ||
}); | ||
Requests to the collection (not its members) take standard MongoDB query parameters to filter the documents based on custom criteria. | ||
$.ajax({ | ||
type: 'GET', | ||
dataType: 'json', | ||
url: '/api/v1/vegetables', | ||
data: { | ||
conditions: JSON.stringify({ | ||
color: 'red', | ||
'nutrition.sodium': { $lte: 10 } | ||
}) | ||
} | ||
}).done(function (vegetables) { | ||
console.dir(vegetables); | ||
}); | ||
Examples with Backbone: | ||
var Vegetables = Backbone.Collection.extend({ | ||
url: '/vegetables', | ||
// This method stringifies 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); | ||
} | ||
}); | ||
var Vegetable = Backbone.Model.extend({ | ||
urlRoot: '/vegetables' | ||
}); | ||
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 }, | ||
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. | ||
`bacuis.rest` | ||
------------- | ||
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. | ||
@@ -78,2 +173,14 @@ | ||
RESTful Headers | ||
--------------- | ||
* `Accept: application/json` is set for all responses. | ||
* The `Allow` header is set automatically, correctly removing HTTP verbs when | ||
those verbs have been disabled with e.g. `put: false`. | ||
* The `Location` HTTP header is set for PUT and POST responses. | ||
* If `relations: true` is passed to `baucis.rest`, HTTP link headers will be set for all responses. | ||
Controllers | ||
----------- | ||
`baucis.rest` returns an instance of the controller created to handle the schema's API routes. | ||
@@ -122,51 +229,2 @@ | ||
Also note that Mongoose middleware will be executed as usual. | ||
Vegetable.pre('save', function () { ... }); | ||
Examples | ||
-------- | ||
Requests to the collection (not its members) take standard MongoDB query parameters to filter the documents based on custom criteria. | ||
Examples with jQuery: | ||
$.getJSON('/api/v1/vegetables/4f4028e6e5139bf4e472cca1', function (data) { | ||
console.log(data); | ||
}); | ||
$.ajax({ | ||
type: 'POST', | ||
dataType: 'json', | ||
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' }) } | ||
}).done(function (vegetables) { | ||
console.dir(vegetables); | ||
}); | ||
An example with Backbone: | ||
var Vegetables = Backbone.Collection.extend({ | ||
url: '/vegetables', | ||
baucis: function (query) { | ||
return this.fetch({ data: { query: JSON.stringify(query) } }); | ||
} | ||
}); | ||
var Vegetable = Backbone.Model.extend({ | ||
urlRoot: '/vegetables' | ||
}); | ||
var redVeges = new Vegetables(); | ||
redVeges.baucis({ color: 'red' }).then(function () { ... }); | ||
Contact Info | ||
@@ -173,0 +231,0 @@ ------------ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
269558
985
234