The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
@[Cocaine::Route(path: "/", verb: "GET")]
def controller_index(context : HTTP::Server::Context, params : Cocaine::Param)
context.response.content_type = "text/plain"
context.response.print "Hello world, got #{context.request.path} !"
end
@[Cocaine::Route(path: "/user/:id", verb: "GET")]
def controller_user(context : HTTP::Server::Context, params : Cocaine::Param)
context.response.content_type = "text/plain"
context.response.print "Hello world, got #{context.request.path} !"
end
################################################################################
# Server
################################################################################
server = HTTP::Server.new { |context| Cocaine.match_endpoint context }
server.listen "0.0.0.0", 5000
HTTP::Server
, so to be faster than that you might need to get creative
GC.malloc*
and it segfaults only with -Dpreview_mt when calling an empty function. https://github.com/didactic-drunk/fiber_stats.cr/pull/1#discussion_r665800802
.as
wouldn't handle over/underflows, so id deff use .to_i32
, or really just .to_i
.as(Int32)
can be useful if the type of your value is like Int32 | Bool
and you want to tell the compiler "i know it'll be an Int32 in the case"