@sdogruyol
paris.rb
07.06.2016
Serdar Doğruyol
Lead Developer - Protel Turkey
@sdogruyol
http://kemalcr.com
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
# 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
<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
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
http://www.crystalforrubyists.com
@sdogruyol
https://slides.com/sdogruyol/building-web-apps-with-kemal-parisrb