Created
January 10, 2013 17:13
-
-
Save ruzzbot/4503926 to your computer and use it in GitHub Desktop.
ss-restrpc : a socketstream module that creates rest services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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