Building Web Applications with
Kemal
@sdogruyol
paris.rb
07.06.2016
Serdar Doğruyol
Lead Developer - Protel Turkey
@sdogruyol
- Rubyist, Crystal enthusiast
- Ruby Turkey, Crystal Turkey Organizer
- Open source developer
- Literally Polyglot
we <3 ruby
Expressive
Powerful
OOP
+
The superb performance of C
we <3 crystal
Kemal
http://kemalcr.com
Simple
Fast
Featured
- RESTful
- Built-in WebSocket
- JSON
- Static File Serving
- Pluggable Middlewares
- View templating
require "kemal"
get "/" do
.. show something ..
end
post "/" do
.. create something ..
end
put "/" do
.. replace something ..
end
patch "/" do
.. modify something ..
end
delete "/" do
.. annihilate something ..
end
Kemal.run
REST
WebSocket
# A simple chat server
require "kemal"
messages = [] of String
sockets = [] of HTTP::WebSocket
public_folder "src/assets"
get "/" do
render "src/views/index.ecr"
end
ws "/" do |socket|
sockets.push socket
socket.on_message do |message|
messages.push message
sockets.each do |s|
s.send messages.to_json
end
end
end
http://kemal-react-chat.herokuapp.com
View Engine
<h1>This is just like ERB!</h1>
<p>Let's run some Crystal Code</p>
<% some_var = "Serdar %>
<%= Process.pid %>
ECR
h1 This is just like HAML!
p Let's run some Crystal code.
- some_var = "Serdar"
= Process.pid
Slang
Fast
Framework | Requests Per Sec | Avg. Resp. Time |
---|---|---|
Kemal(Production) | 100238 | 395.44μs |
Sinatra(Puma) | 2274 | 43.82ms |
get "/" do
"Hello world!"
end
HTTP
Framework | CPU (%) | Memory (MB) |
---|---|---|
Crystal(Kemal) | 1.85 | 11.2 |
ws (Node) | 38.95 | 906.3 |
Websocket
https://gist.github.com/sdogruyol/bdd400a6eac13e26228e
Who uses Kemal
Crystal for Rubyists
http://www.crystalforrubyists.com
Questions?
Thanks!
@sdogruyol
https://slides.com/sdogruyol/building-web-apps-with-kemal-parisrb
Building Web Applications with Kemal
By Serdar Dogruyol
Building Web Applications with Kemal
- 2,327