Last active
August 29, 2015 14:05
-
-
Save leafo/9c63cc81357c66d00ad2 to your computer and use it in GitHub Desktop.
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
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