Skip to content

Instantly share code, notes, and snippets.

Created February 10, 2011 12:15
Show Gist options
  • Save anonymous/820427 to your computer and use it in GitHub Desktop.
Save anonymous/820427 to your computer and use it in GitHub Desktop.
API draft for simple RESt server for node.js in coffeescript
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