Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

baucis

Package Overview
Dependencies
Maintainers
1
Versions
202
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

baucis - npm Package Compare versions

Comparing version 0.2.3-1 to 0.2.3-2

2

package.json
{
"name": "baucis",
"version": "0.2.3-1",
"version": "0.2.3-2",
"main": "index.js",

@@ -5,0 +5,0 @@ "scripts": {

@@ -1,2 +0,2 @@

baucis v0.2.3-1
baucis v0.2.3-2
===============

@@ -16,2 +16,9 @@

Usage
-----
To install:
npm install baucis
An example of creating a REST API from a Mongoose schema:

@@ -47,23 +54,46 @@

`baucis.rest` returns an instance of the controller created to handle the schema's routes.
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.
var controller = baucis.rest({
singular: 'foo'
baucis.rest({
singular: 'vegetable',
all: function (request, response, next) {
if (request.isAuthenticated()) return next();
return response.send(401);
}
});
Or, set some middleware for specific HTTP verbs or disable verbs completely:
baucis.rest({
singular: 'vegetable',
get: [middleware1, middleware2],
post: middleware3,
del: false,
put: false
});
`baucis.rest` returns an instance of the controller created to handle the schema's API routes.
var subcontroller = baucis.rest({
singular: 'bar',
publish: false, // don't add routes automatically
restrict: function (query, request) { // allows direct access to the Mongoose queries
query.where({ parent: request.params.fooId });
basePath: '/:fooId/bars'
publish: false, // don't add API routes automatically
restrict: function (query, request) {
// Only retrieve bars that are children of the given foo
query.where('parent', request.params.fooId);
}
});
// Embed the subcontroller at /foos/:fooId/bars
controller.use('/:fooId/bars', subcontroller);
var controller = baucis.rest({
singular: 'foo',
configure: function (controller) {
// Embed the subcontroller at /foos/:fooId/bars
controller.use(subcontroller);
// Embed arbitrary middleware at /foos/:fooId/qux
controller.use('/:fooId/qux', function (request, response, next) {
// Do something cool…
next();
// Embed arbitrary middleware at /foos/qux
controller.use('/qux', function (request, response, next) {
// Do something cool…
next();
});
}
});

@@ -74,5 +104,10 @@

var controller = baucis.rest({
singular: 'robot'
singular: 'robot',
configure: function (controller) {
// Add middleware before all other rotues in the controller
controller.use(express.cookieParser());
}
});
// Add middleware after default controller routes
controller.use(function () { ... });

@@ -84,2 +119,9 @@ controller.set('some option name', 'value');

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.

@@ -102,31 +144,27 @@

An example with Backbone:
var Foos = Backbone.Collection.extend({
url: '/foos'
$.ajax({
type: 'GET',
dataType: 'json',
url: '/api/v1/vegetables',
data: { query: JSON.stringify({ color: 'red' }) }
}).done(function (vegetables) {
console.dir(vegetables);
});
var Bar = Backbone.Model.extend({
urlRoot: '/bars'
});
An example with Backbone:
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.
baucis.rest({
singular: 'vegetable',
all: function (request, response, next) {
if (request.isAuthenticated()) return next();
return response.send(401);
var Vegetables = Backbone.Collection.extend({
url: '/vegetables',
baucis: function (query) {
return this.fetch({ data: { query: JSON.stringify(query) } });
}
});
Or, set some middleware for specific HTTP verbs:
baucis.rest({
singular: 'vegetable',
get: [middleware1, middleware2],
post: middleware3,
del: [middleware4, middleware5]
var Vegetable = Backbone.Model.extend({
urlRoot: '/vegetables'
});
var redVeges = new Vegetables();
redVeges.baucis({ color: 'red' }).then(function () { ... });
Contact Info

@@ -133,0 +171,0 @@ ------------

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc