![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
restful-goose
Advanced tools
A new improved version of your favorite API framework for mongoose/MongoDB
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: ${VERSION}
undefined
was being passed where an array was expected. This has been fixed.npm install restful-goose
Version 2 of RESTful Goose is much easier to use. The constructor only requires 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);
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);
It is now possible to pass an options object with a models
key that contains an array of mongoose Model constructors (so not Document instances, but the actual Model class you invoke with the mongoose.model()
method).
Use this if you only want to make some models available via the API. WARNING: this is a beta feature and isn't yet fully implemented. As of now, only top level endpoints are disabled. Relationship objects still populate
even if a model isn't included in the API.
FAQs
A new improved version of your favorite API framework for mongoose/MongoDB
The npm package restful-goose receives a total of 11 weekly downloads. As such, restful-goose popularity was classified as not popular.
We found that restful-goose demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.