Skip to content

Instantly share code, notes, and snippets.

@jwoertink
Created November 2, 2016 19:54
Show Gist options
  • Save jwoertink/3a973ee51c2e689adb4e6c7ae31e3ff5 to your computer and use it in GitHub Desktop.
Save jwoertink/3a973ee51c2e689adb4e6c7ae31e3ff5 to your computer and use it in GitHub Desktop.
require "kemal"
class AuthorizationHandler < HTTP::Handler
ACCEPT = "application/vnd.api.v1+json"
def call(env)
if env.request.headers["Accept"] != ACCEPT
env.response.status_code = 401
end
call_next(env)
end
end
Kemal.config.add_handler(AuthorizationHandler.new)
error 401 do
{"error" => "Unauthorized"}.to_json
end
get "/" { {"success" => "YAY"}.to_json }
Kemal.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment