A slightly more interesting example is an HTTP Server:
require "http/server" server = HTTP::Server.new do |context| context.response.content_type = "text/plain" context.response.print "Hello world! The time is #{Time.local}" end address = server.bind_tcp 8080 puts "Listening on http://#{address}" server.listen
The above code will make sense once you read the whole language reference, but we can already learn some things.
require "http/server"
server = HTTP::Server.new ...
address = server.bind_tcp 8080
HTTP::Server.new ... ... Time.local ... address = server.bind_tcp 8080 ... puts "Listening on http://#{address}" ... server.listen
HTTP::Server.new do |context| ... end
"Hello world! The time is #{Time.local}"
To the extent possible under law, the persons who contributed to this workhave waived
all copyright and related or neighboring rights to this workby associating CC0 with it.
https://crystal-lang.org/docs/getting_started/http_server.html