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

Module for automatically creating REST interfaces for mongoose schemata

  • 0.0.0
  • npm
  • Socket score

Version published
Weekly downloads
20
decreased by-91.27%
Maintainers
1
Weekly downloads
 
Created
Source

baucis

David Rjckaert III - Philemon and Baucis Giving Hospitality to Jupiter and Mercury

David Rijckaert - Philemon and Baucis Giving Hospitality to Jupiter and Mercury

Like Baucis and Philemon of old, this library provides REST to the weary traveler. Automatically creates REST services from Mongoose models:

var Vegetable = new Schema({
  name: String
});

Vegetable.metadata({
  singular: 'vegetable',
  plural: 'vegetables'
});

var app = express.createServer();
app.configure(function(){
  app.use(express.bodyParser());
});

// create RESTful routes
app.rest(Vegetable);

app.listen(80);

Later make requests:

  • GET /vegetable/:id — get the addressed document

  • POST /vegetable/:id — currently unimplemented (in the future will push the data into a field specified for the addressed object)

  • PUT /vegetable/:id — create or update the given document

  • DEL /vegetable/:id — delete the addressed object

  • GET /vegetables/ — get all documents (in the future will accept query args to pass to the mongo server)

  • POST /vegetables/ — creates a new object and sends back its ID

  • PUT /vegetables/ — replace all documents with given new documents

  • DEL /vegetables/ — delete all documents (also will accept query args in future)

Examples with jQuery:

$.getJSON('/vegetable/4f4028e6e5139bf4e472cca1', function (data) {
  console.log(data);
});

$.ajax({
  type: 'POST',
  dataType: 'json',
  url: '/vegetables/',
  data: { name: 'Potato' }
}).done(function( id ) {
  console.log(id);
});

app.rest will accept arrays, hashes, or single Schema objects. An example with require-index:

var schemata = requireindex('./schemata');
app.rest(schemata);

Use middleware for security, etc. Middleware is plain old Connect middleware, so it can be used with pre-existing modules like passport. Set the middleware metadata to a function or array of functions.

Vegetable.metadata({
  singular: 'vegetable',
  plural: 'vegetables',
  middleware: function(request, response, next) {
    if (request.isAuthenticated()) return next();
    else return response.send(401);
  }
});

Contact Info

  • http://william.nodejitsu.com/
  • @wprl

© 2012 William P. Riley-Land Licensed under the GPL v3
Please fork and create issues!

FAQs

Package last updated on 14 Jul 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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