DEV Community

Rayan Desfossez
Rayan Desfossez

Posted on

Crystal 1.0

Crystal is a language that caught my eye recently

Overall, now that it is in 1.0, do you think we can adopt it with Amber to write web applications and use it as a new language for our proxies?

Top comments (4)

Collapse
 
jgaskins profile image
Jamie Gaskins

By "proxies", do you mean HTTP proxies?

Collapse
 
rayandfz profile image
Rayan Desfossez

Yes

Collapse
 
jgaskins profile image
Jamie Gaskins

In that case, frameworks like Amber or Lucky are probably overkill. I would probably stick with using HTTP::Server directly:

require "http"

class Proxy
  include HTTP::Handler

  def call(context : HTTP::Server::Context)
    # Do proxy things here
  end
end

http = HTTP::Server.new([
  HTTP::LogHandler.new, # Log requests
  HTTP::CompressHandler.new, # Gzip/Deflate response bodies
  Proxy.new,
])
http.listen "0.0.0.0", 8080
Enter fullscreen mode Exit fullscreen mode

All of your PROXY protocol things would happen inside of (or downstream from) the Proxy#call method. The context passed to that method contains references to the request and response objects. You'd be able to stream things from the destination back to the requestor to keep your TTFB and memory footprint low, whereas I believe Amber builds the entire response in memory before sending it over the network.

Collapse
 
imeraj profile image
Meraj

I played with Amber a bit and I think it’s a great framework. Very much like Rails. I would love to see this framework develop further and with a bit faster pace! Thanks