Skip to content

Instantly share code, notes, and snippets.

@Dykam
Forked from anonymous/rest.coffee
Created February 10, 2011 16:23
Show Gist options
  • Save Dykam/820816 to your computer and use it in GitHub Desktop.
Save Dykam/820816 to your computer and use it in GitHub Desktop.
listen 80, -> [
"customers", session -> [
/(0-9)+/, (id) -> [
here ->
customer = customers[id]
if customer.isPrivate and @session.user.id isnt customer.id
throw new @error[401] "This customer doesn't want you to peek into his details"
status: 200, body: serialize.toJson customer
]
]
"products", session -> [
@regex /(0-9)+/, (id) ->
]
session.management url: "session", assign: "session"
@catch @error[404], (error) ->
# handle error gracefully
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment