kemal/docs/middlewares.md

37 lines
707 B
Markdown
Raw Normal View History

2015-12-16 18:32:01 +00:00
# Middlewares
2015-12-27 10:05:19 +00:00
## Built-in Middlewares
Kemal has built-in middlewares for common use cases.
### HTTP Basic Authorization
2015-12-27 10:55:49 +00:00
This middleware lets you add HTTP Basic Authorization to your Kemal application.
2015-12-27 10:08:14 +00:00
You can easily use this middleware with `basic_auth` macro like below.
2015-12-27 10:05:19 +00:00
```crystal
require "kemal"
basic_auth "username", "password"
get "/" do
"This won't render without correct username and password."
end
```
## Custom middlewares
You can create your own middleware by inheriting from ```HTTP::Handler```
2015-12-16 18:32:01 +00:00
```crystal
class CustomHandler < HTTP::Handler
def call(request)
puts "Doing some custom stuff here"
call_next request
end
end
Kemal.config.add_handler CustomHandler.new
```