Created
November 3, 2016 21:59
-
-
Save jc00ke/3d0590a9227e960a06f34b5abed5b759 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
require "json" | |
require "kemal" | |
macro build_routes(hash) | |
{% for route, info in hash %} | |
{{info[:method].id}} {{route}} do |env| | |
# originally I had info[:method] but that would kick out "put" | |
# but changing to info[:method].id kicked out put, which worked. | |
env.response.status_code = {{info[:status_code]}} | |
env.response.content_type = "application/json" | |
{{info[:body]}}.to_json | |
end | |
{% end %} | |
end | |
build_routes({ | |
"/widgets/:widget_id" => { | |
:method => "put", | |
:status_code => 200, | |
:body => {foo: 1}, | |
} | |
}) | |
Kemal.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, that makes sense. I ended up getting rid of that var anyway.