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

extremo

v0.0.25

Published

Another RESTful API requests handler. For express/mongoose based applications. Extended.

Downloads

4

Readme

Install

$ npm i remo

Usage

First of all, you need to define your Mongoose models. You don't need to pass them to Remo, just make them available through mongoose.model().

Then, serve your application:

var express = require('express')
  , models = require('./models') // <- here your models are defined.
  , http = require('http')
  , remo = require('remo')
  , app = express()

app.configure(function() {
  // Hold my beer, nginx.
  app.set('port', process.env.PORT || 80)

  // More paths & middleware configuration here.
  // Check any express.js application for details.
})

remo.serve(app, {url: '/api', mongooseUri: 'mongodb://localhost/test'})

http.createServer(app.listen(app.get('port')), function() {
  console.log('He is alive!')
})

Done, here's the API:

  • GET http://localhost/api/thing - list things
  • GET http://localhost/api/thing/count - count things
  • GET http://localhost/api/thing/123 - get thing (id = 123)
  • POST http://localhost/api/thing - create thing
  • PUT http://localhost/api/thing/123 - update thing (id = 123)
  • DELETE http://localhost/api/thing/123 - delete thing (id = 123)

API

Remo provides just a single public method serve. Arguments are:

  • app - Express application instance.
  • _options - Serving options hash.

Options

  • url - URL prefix for a REST requests. Defaults to '/remo'.

  • debug - Debug mode state. Defaults to false.

  • mongoose - Existing Mongoose connection reference. If empty, the module will try to open connection using mongooseUri.

  • mongooseUri - Mongoose connection URI. Will be ignored if 'mongoose' option is set.

  • countAction - Url suffix for COUNT action. Defaults to 'count'. Because of using the same URL pattern as for GET action (/:alias/:id) the COUNT action may blocks getting an entity with ID = 'count' (kekeke). Override this option with something like '_count' or '__count' (or even '___count'!) if so. Then COUNT url will looks like '/thing/_count'.

  • aliasToName - By default, remo converts entity name from URL to "uppercase-first" form:

    • mything -> Mything
    • my_thing -> My_thing
    • MyThing -> MyThing

You can pass your own converter in aliasToName option, like so:

function myAliasToName(alias) {
  return alias.strToUpper()
}
remo.serve(app, {mongoose: mongoose, aliasToName: myAliasToName})
  • callbacks - A hash of callback functions for actions. Keys of the hash are model names. Values are hashes with action names as keys and callback functions as values (I don't understand it too). A context of each callback is document instance. Example:
var callbacks = {
  'Thing': {
    'create': function() {
      console.log('Thing #' + this._id + ' created')
    }
  },
  'OtherThing': {
    'update': function() {
      console.log('OtherThing #' + this._id + ' updated')
    }
  },
}

Actions

LIST

Retrieve an entities list. URL: GET /:alias.

req.params:
  + alias: Entity name
req.query:
  + find (where,q) : Search condition
  + limit (lim)    : Limit value
  + populate (pop) : Population expression
  + skip           : How much results should be skipped
  + sort           : Sort expression

COUNT

Retrieve an entities count. URL: GET /:alias/count (Suffix is overrideable, see options.countAction).

req.params:
  + alias: Entity name
req.query:
  + find (where,q) : Search condition

GET

Retrieve an entity by ID. URL: GET /:alias/:id.

req.params:
  + alias: Entity name
  + id:    Entity ID
req.query:
  + populate: Population expression

CREATE

Create an entity. URL: POST /:alias.

req.params:
  + alias: Entity name
req.body: Attributes hash

UPDATE

Update an entity by ID. URL: PUT /:alias/:id.

req.params:
  + alias: Entity name
  + id:    Entity ID
req.body: Attributes hash

DELETE

Delete an entity by ID. URL: DELETE /:alias/:id.

req.params:
  + alias: Entity name
  + id:    Entity ID