Skip to content

Instantly share code, notes, and snippets.

@ruzzbot
Created January 10, 2013 17:13
Show Gist options
  • Save ruzzbot/4503926 to your computer and use it in GitHub Desktop.
Save ruzzbot/4503926 to your computer and use it in GitHub Desktop.
ss-restrpc : a socketstream module that creates rest services
express = require 'express'
app = module.exports = express()
prefix = "api"
# The collection of models
models =
"writeoff": require '../models/writeoff'
###
# Create http interface for a model.<namespace>
# @param.namespace "string" : The filename of the model and Used to create the http-path.
# @param.actions "array" : A string of keys that match available methods on model.<namespace>.
###
httpRPC_factory = (namespace, actions)->
for action in actions
app.get "/#{prefix}/#{namespace}/#{action}", (req, res)->
path = req.route.path.split "/"
models["#{namespace}"]["#{path[path.length-1]}"] req.params, ()->
res.send arguments[0]
# CREATE HTTP RPCS HERE
# create_http_RPC "<namespace>", [ "array of keys","associated with model: models.<namespace>"]
#
httpRPC_factory "writeoff", [ "Teams", "YTD", "YTDValue", "YTDPercent", "UnbilledHours", "RollingBilledHours" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment