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 🙏

© 2026 – Pkg Stats / Ryan Hefner

coffeerest-api

v0.1.35

Published

Api scaffolding from a model specification in few lines of coffeescript OH MY

Readme

coffeerest-api

Unfancy rest apis

Ouch! Is it that simple?

Your model.coffee specification

module.exports = 
  host: process.env.HOST || "localhost:8080"
  name: "project foo"
  resources:
    '/book/:category':
      post:
        description: 'adds a book'
        payload:
          foo: { type: "string", minLength: 5, required: true }
        function: (req, res, next,lib, reply) ->
          category = req.params.category
          reply.data = [1,2, lib.foo() ]
          return reply 
          
  replyschema:
    type: 'object'
    required: ['code','message','kind','data']
    messages:
      0: 'feeling groovy'
      1: 'unknown error'
      2: 'your payload is invalid (is object? content-type is application/json?)'                                                                                           
      3: 'data error'
      4: 'access denied'
    payload:
      code:       { type: 'integer', default: 0 }
      message:    { type: 'string',  default: 'feeling groovy' }
      kind:       { type: 'string',  default: 'default', enum: ['book','default'] }
      data:       { type: 'object' }
      errors:     { type: 'object' }

Extensions

  • coffeerest-api-doc: automatic html and markdown REST-documentation
  • coffeerest-api-clients: automatic REST clients) TODO
  • coffeerest-api-db: ORM to connect any database (using waterline) which automatically generates collection-to-restapi-endpoints

Example servercode

restify    = require('restify')        # here we use restify but express should be fine too
coffeerest = require('coffeerest-api')
model      = require('./model.coffee')
lib        = 
  foo: () -> return 3

server = restify.createServer { name:model.name }
server.use restify.queryParser()
server.use restify.bodyParser()
server.use coffeerest server, { "/v1":model }, lib  # multiversion support
server.listen process.env.PORT || 8080, () ->
  console.log '%s listening at %s', server.name, server.url

Done!

$ coffee server.coffee
registering REST resource: /v1/books/:action (post)
registering REST resource: /v1/book (post)
project foo listening at http://0.0.0.0:4455

$ curl -H 'Content-Type: application/json' http://localhost:$PORT/v1/book -X POST --data '{"foo":"foobar"}'
{"code":0,"message":"feeling groovy","kind":"default","data":[1,2,3],"errors":{}}

$ curl -H 'Content-Type: application/json' http://localhost:$PORT/v1/book -X POST --data '{"foo":"foo"}'
{"code":2,"message":"your payload is invalid (is object? content-type is application/json?)","kind":"default","data":{},"errors":[{"uri":"/foo","message":"String is less than the required minimum length","attribute":"minLength","details":5}]}

$ curl -H 'Content-Type: application/json' http://localhost:$PORT/v1/book -X POST --data '{}'
"code":2,"message":"your payload is invalid (is object? content-type is application/json?)","kind":"default","data":{},"errors":[{"uri":"/foo","message":"Property is required","attribute":"required","details":true}]}

Philosophy

Dont generate code based on config (Yeoman etc), but instead extend both code and config. Oh..and jsonschema, because jsonschema.

Magic

  • ignore certain extensions

| pass environment var COFFEEREST_EXT_IGNORE with value '(db|frontend)' to ignore all coffeerest extensions which match either 'db' or 'frontend'