Created
February 10, 2011 12:15
-
-
Save anonymous/820427 to your computer and use it in GitHub Desktop.
API draft for simple RESt server for node.js in coffeescript
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
listen 80, -> [ | |
session @constant "customers", -> [ | |
@regex /(0-9)+/, (id) -> [ | |
here -> | |
customer = customers[id] | |
if customer.isPrivate and @session.user.id isnt customer.id | |
throw @error[401] "This customer doesn't want you to peek into his details" | |
status: 200, body: serialize.toJson customer | |
] | |
], | |
session @constant "products", -> [ | |
@regex /(0-9)+/, (id) -> | |
], | |
(root, url...) -> | |
return false if "foo" isnt root | |
status: 200, body: "You are in /foo, the subpart you requested is #{url.join('/')}" | |
session.management url: "session", assign: "session", | |
@catch (url...) -> | |
throw @error[404] "Uh oh, this page does not exists." | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment