DEV Community

Ciro Spaciari
Ciro Spaciari

Posted on

Faster and simple Http and WebSocket Server for Ruby

uWebSockets for Ruby - uWebSockets.rb

I started to implement uWebSockets C API wrapper and a Ruby version a few days ago.
I got some good performance results (about 5x agoo in using techempower benchmarks for plaintext), for now i just implemented http/https apis but i will implement websockets this week and write some documentation (only linux support, mac should works fine as well, but i will add windows and mac tests and support too)

I will be glad for some feedback and help for testing in the near future https://github.com/cirospaciari/uWebSockets.rb

Overly simple hello world app

require "uws"

UWS::App.new()
.get("/", lambda {|response, request| response.end("Hello World uWS from Ruby!")})
.listen(8082, lambda {|config| puts "Listening on port #{config.port}" })
.run()
Enter fullscreen mode Exit fullscreen mode

Gemfile

gem 'uws', git: 'https://github.com/cirospaciari/uWebSockets.rb.git', branch: 'main', submodules: true
Enter fullscreen mode Exit fullscreen mode

Run

bundle exec ruby ./hello_world.rb
Enter fullscreen mode Exit fullscreen mode

SSL version sample

require "uws"

UWS::SSLApp.new({
    key_file_name: "./misc/key.pem",
    cert_file_name: "./misc/cert.pem", 
    passphrase: "1234"
})
.get("/", lambda {|response, request| response.end("Hello World uWS from Ruby!")})
.listen(8082, lambda {|config| puts "Listening on port #{config.port}" })
.run()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)