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 🙏

© 2025 – Pkg Stats / Ryan Hefner

restrant

v0.0.22

Published

Framework for presentation on node.js

Downloads

3

Readme

これは何ですか?

node.jsでサーバとクライアントを繋ぐ通信の部分で楽をする為のライブラリです。 RoRのroute.rbのような記述をすることでリクエストをコントローラに定義したアクションへマッピングします (URLだけではなく、リクエストパラメータやポストパラメータもパターン情報に使います)。

どんな機能がありますか?

  • サーバー側のコントローラーを通信用スタブクラスとしてクライアント用のJSファイルとして生成します。
  • RestfulなURLの公開が簡単に行えます。これにより、Backbone.jsのsyncの機能と相性が良いです。
  • MongooseのSchema情報を元にBackbone.jsからモデルまで通して生成される仕組みを作成中です (仕様が固まっていないので大きく変更される可能性があります)。

何に依存していますか?

  • underscore
  • node-promise
  • mongoose
  • express(expressのroutesの置き換えを目指していますが、今はroutesから呼ぶ形式になっています。middlewareを書けば良さそうですが手が回っていません)

簡単なルート定義の例はありますか?

例えば以下のような感じになります。

var restrant = new Restrant();

// 利用されるコントローラを読み込む
var SampleController = require('../app/controller/sample_controller').SampleController;
var SnakeCaseController = require('../app/controller/snake_case_controller').SnakeCaseController;
var RestfulController = require('../app/controller/restful_controller').RestfulController;
var MongooseController = require('../app/controller/mongoose_controller').MongooseController;

// 公開コントローラと、コントローラのラベルを指定します(省略可)
// コントローラの実装についてはサンプルから辿って下さい。
restrant.publishController('sample', SampleController); //with keyname
restrant.publishController(SnakeCaseController); // keyname = snake_case
restrant.publishController(RestfulController);
restrant.publishController(MongooseController);

// Restfulにしたければrestfulメソッドを呼びます。一般的なリクエストに対応できるはずです。
restrant.restful({path: '/api/restful', controller:'restful'}); //for restful syntax sugar
restrant.restful({path: '/api/mongoose', controller: 'mongoose'}); //for mongoose mixed in controller

//
restrant.on({path:'/api/:controller/:id:Integer', action:'selectById'}); //api/sample/123
restrant.on({path:'/api/sample/', controller:'sample', action:'get', method:'GET'}); //api/sample/get
restrant.on({path:'/api/sample/', controller:'sample', action:'post', method:'POST'}); //api/sample/get
restrant.on({path:'/api/:test/multiple/:id', controller:'sample', action:'withparam', method:'POST'}); //api/sample/get
restrant.on({path:'/api/:controller/', action:'test'}); //api/snake_case

// create stub
restrant.stub({path:'/client.js', namespace:'TESTNS'}); // for browser

簡単なコントローラの例はありますか?

Restful対応する為のコントローラは下記のようになります。

function RestfulController(req, res) {
    this.req = req;
    this.res = res;
}

_.extend(RestfulController.prototype, {

    doGet: function(params){
        // 好きな処理を入れて下さい。プロミスをreturnするか、この関数内でレスポンスを返して下さい。
        return promise.delay(1).then(function(){
            return {id:'GET:' + params.id};
        });
    },

    doPost: function(params){
        // 好きな処理を入れて下さい。プロミスをreturnするか、この関数内でレスポンスを返して下さい。
        return promise.delay(1).then(function(){
            return {id:'POSTED'};
        });
    },

    doPut: function(params){
        // 好きな処理を入れて下さい。プロミスをreturnするか、この関数内でレスポンスを返して下さい。
        return promise.delay(1).then(function(){
            return {put: 'already put'};
        });
    },

    doDelete: function(params){
        // 好きな処理を入れて下さい。プロミスをreturnするか、この関数内でレスポンスを返して下さい。
        return promise.delay(1).then(function(){
            return {delete: 'success'};
        });
    }
});