Skip to content

Instantly share code, notes, and snippets.

@leafo
Last active August 29, 2015 14:05
Show Gist options
  • Save leafo/9c63cc81357c66d00ad2 to your computer and use it in GitHub Desktop.
Save leafo/9c63cc81357c66d00ad2 to your computer and use it in GitHub Desktop.
lapis = require "lapis"
import capture_errors from require "lapis.application"
import assert_valid from require "lapis.validate"
import json_params from require "lapis.application"
class App extends lapis.Application
"/test": json_params capture_errors {
on_error: =>
json: @errors, status: 401
=>
assert_valid @params, {
{"hello", exists: true}
}
"ok"
}
----------------------------------
-- turn it into a helper:
api_method = (fn) ->
json_params capture_errors {
on_error: =>
json: @errors, status: 401
fn
}
class App extends lapis.Application
"/test-one": api_method =>
assert_valid @params, {
{"hello", exists: true}
}
"/test-two": api_method =>
assert_valid @params, {
{"world", exists: true}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment