npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

monsoon

v0.1.4

Published

Allows for easy & extensible CRUD REST API generation using Express & Mongoose

Downloads

10

Readme

Monsoon

Extensible REST API Generator

Monsoon allows for easy, extensible CRUD REST API generation using Express & Mongoose.

Installation

$ npm install monsoon

Monsoon requires both express and mongoose.

Quick Start

Using monsoon is easy. Let's assume you have a Schema called Product. Your API router might look something like this:

var express = require('express')
    , monsoon = require('monsoon')
    , mongoose = require('mongoose')
    , Product = mongoose.model('Product')
    , app = module.exports = express();

// Resources
app.use( '/products', monsoon.router(Product).export() );

That's it! You now have routes in place for some of the more common REST operations.

Routes

Currently, Monsoon will generate the following routes & controllers. All various responses and the HTTP codes associated with them have been included.

METHOD /PATH (example)

Params: any URL parameters the method requires
Body: any URL parameters the method requires
Returns: ### what the controller returns in the response body

GET /

Returns: 200 a JSON array of all documents in the collection
Returns: 500 an error string

POST /

Body: a JSON representation of the document to be created
Returns: 200 a JSON representation of the created document
Returns: 409 an error string
Returns: 500 an error string

GET /:id

Params: a 24-character Mongo ID
Returns: 200 a JSON representation of the document in the collection with the given ID
Returns: 404
Returns: 500 an error string

PUT /:id

Params: a 24-character Mongo ID
Body: a JSON representation of the updated document
Returns: 200 a JSON representation of the updated document
Returns: 404
Returns: 500 an error string

PATCH /:id

Params: a 24-character Mongo ID
Body: a JSON object containing the fields & values to update the document with
Returns: 200 a JSON representation of the updated document
Returns: 404
Returns: 500 an error string

DELETE /:id

Params: a 24-character Mongo ID
Returns: 204
Returns: 404
Returns: 500 an error string

Extending Monsoon Controllers

So you want to add some routes of your own to Monsoon's defaults? No problem, let's just change our API router to look something like this

var express = require('express')
    , monsoon = require('monsoon')
    , app = module.exports = express();

// Resources
app.use( '/products', monsoon.app(require('./products') );

And create a products.js file, which will look something like this:

var monsoon = require('monsoon')
    , controller = module.exports = monsoon.controllers('Product');

// Custom Controllers
controllers.get('/status', function(req, res) {
    res.json({
        status: 'online'
    })
});

And there you have it. Define any routes you wish on the controllers object just as you would an Express app (var app = express() is common)

Additional Features

//TODO

Support

The following are known issues and will be addressed soon

  • Multiple controller callbacks/middleware ( app.get('/path', middlewareFunction, function(req, res) { ... }) )

Contact & License Info

Author: Matthew Balmer
Twitter: @mattbalmer
Website: http://mattbalmer.com
License: MIT