New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

restful-goose

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restful-goose

A new improved version of your favorite API framework for mongoose/MongoDB

  • 2.0.41
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
decreased by-87.88%
Maintainers
1
Weekly downloads
 
Created
Source

RESTful Goose

Yet another RESTful microservice generator for Mongoose with an emphasis on flexibility. This API uses the JSON API spec and supports optional child models.

Version: 2.0.0-beta1

Major Update - Version 2.0.0

2.0.0 is a complete rewrite of RESTful Goose. It takes what I learned from building 1.x and does everything in a much more efficient and powerful way.

However, 2.x is COMPLETELY incompatible with 1.x so please take care when updating your application.

Installation

npm install restful-goose

Use

Version 2 of RESTful Goose is much easier to use. The constructor only accepts one argument: a Mongoose Connection.

var restfulGoose = require('restful-goose');
var mongoose = require('mongoose');

mongoose.connect('localhost');
restfulGoose(mongoose).listen(3000);

Your API will be listening for connections on port 3000.

Alternatively, and probably the more common use, would be to mount RESTful Goose under your existing Express app so you can take advantage of authentication middlewares and the like:

var express = require('express');
var restfulGoose = require('restfulGoose');
var mongoose = require('mongoose');

var app = express();
var myMiddleware = [passport.authenticate('bearer'), validateUser];

app.use('/api', myMiddleware, restfulGoose(mongoose));

app.listen(3000);

Customization

The best part about RESTful Goose 2 is the much greater flexibility you have to customize how the app handles individual routes.

Every route goes through an event loop, calling a series of functions that you can hook at nearly every stage of handling a request.

The base restfulGoose export exposes the RouteMap object, which you can copy via the object's extend() method:

/* post-route.js */
var RouteMap = require('restful-goose').RouteMap;

module.exports = RouteMap.extend({
    beforeModel: function(req, res, next) {
        // Modify the query to only return users' own posts
        req.query.user = req.user.id;
    }
});

Then bind your custom map to your restfulGoose instance using the instance's defineRoute() method:

/* app.js */
var restfulGoose = require('restful-goose');
var postRoute = require('./post-route');
// ...

var api = restfulGoose(mongoose);

/* defineRoute(modelName, routeMapObject) */
api.defineRoute('Post', postRoute);

Keywords

FAQs

Package last updated on 20 Sep 2016

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