Created
November 2, 2016 19:54
-
-
Save jwoertink/3a973ee51c2e689adb4e6c7ae31e3ff5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "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