kemal/src/kemal/route.cr

18 lines
546 B
Crystal
Raw Permalink Normal View History

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
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 -> _)
@handler = ->(context : HTTP::Server::Context) do
output = handler.call(context)
output.is_a?(String) ? output : ""
end
2016-07-17 11:43:13 +00:00
end
end
2014-06-11 23:41:02 +00:00
end