2016-07-17 11:43:13 +00:00
|
|
|
module Kemal
|
|
|
|
# Route is the main building block of Kemal.
|
2017-10-06 11:53:53 +00:00
|
|
|
#
|
|
|
|
# It takes 3 parameters: http *method*, *path* and a *handler* to specify
|
2016-07-17 11:43:13 +00:00
|
|
|
# what action to be done if the route is matched.
|
2017-05-14 01:39:11 +00:00
|
|
|
struct Route
|
2017-03-12 16:40:30 +00:00
|
|
|
getter method, path, handler
|
2016-07-17 11:43:13 +00:00
|
|
|
@handler : HTTP::Server::Context -> String
|
2014-06-11 23:41:02 +00:00
|
|
|
|
2017-08-24 20:32:43 +00:00
|
|
|
def initialize(@method : String, @path : String, &handler : HTTP::Server::Context -> _)
|
2016-10-28 08:35:34 +00:00
|
|
|
@handler = ->(context : HTTP::Server::Context) do
|
2017-10-02 20:47:43 +00:00
|
|
|
output = handler.call(context)
|
|
|
|
output.is_a?(String) ? output : ""
|
2016-10-28 08:35:34 +00:00
|
|
|
end
|
2016-07-17 11:43:13 +00:00
|
|
|
end
|
2016-01-13 13:22:50 +00:00
|
|
|
end
|
2014-06-11 23:41:02 +00:00
|
|
|
end
|