Error: no overload matches 'HTTP::Server.new' with type Int32

I was testing the code in the doc:

require "http/server"

server = HTTP::Server.new(8080) do |context|
  context.response.content_type = "text/plain"
  context.response.print "Hello world!"
end

puts "Listening on http://127.0.0.1:8080"
server.listen

But I got the error in the title, I looked up the method signature,
.new (port, &handler : Context -> )

What type is the port?

Thanks.

It should be Int32, I’m thinking this has to be a bug since the overload in the docs there isn’t displayed in the error message’s list. It’s like the self.new constructors aren’t being seen.

There is no constructor accepting port in latest Crystal version.

You are linked to the docs for Crystal 0.23.1

See https://crystal-lang.org/api/0.31.1/HTTP/Server.html#new(handlers:Array(HTTP::Handler),&handler:HTTP::Handler::HandlerProc):self-class-method

1 Like

Where are these docs that you mention?

Oo yea good call, didn’t notice it was a link to older docs

Sorry Sirs, I just clicked a doc link in google results, sorry.

Yes, unfortunately documentation for outdated versions keeps showing up high in search results. We’re working on that in https://github.com/crystal-lang/crystal-website/issues/79

2 Likes