functional web apps with webmachine framework - mikhail bortnyk
TRANSCRIPT
Who am I❖ Mikhail Bortnyk
❖ github: @vessi
❖ twitter: @mikhailbortnyk
❖ language researcher
❖ co-founder of Kottans community school
Who am I❖ Mikhail Bortnyk
❖ github: @vessi
❖ twitter: @mikhailbortnyk
❖ language researcher
❖ co-founder of Kottans community school
❖ 3rd contributor of mruby/c
Who am I❖ Mikhail Bortnyk
❖ github: @vessi
❖ twitter: @mikhailbortnyk
❖ language researcher
❖ co-founder of Kottans community school
❖ 3rd contributor of mruby/c
❖ Ruby developer (not Rails!)
Typical experience of web developer
CGI Old school is cool! (Bash, C, Perl, some scripting)
Servlets I know your pain, bro (PHP, Java)
Typical experience of web developer
CGI Old school is cool! (Bash, C, Perl, some scripting)
Servlets I know your pain, bro (PHP, Java)
MVC The thing we all know (Python/Django, Ruby/Rails etc)
SPA is a new sexy❖ No one uses ol’ goo’ ERB❖ Javascript rules over the web❖ Web does not work without JS
SPA is a new sexy❖ No one uses ol’ goo’ ERB❖ Javascript rules over the web❖ Web does not work without JS❖ http://tobyho.com/
2010/03/11/how-much-of-the-web-actually/
SPA is a new sexy❖ No one uses ol’ goo’ ERB❖ Javascript rules over the web❖ Web does not work without JS❖ http://tobyho.com/
2010/03/11/how-much-of-the-web-actually/
❖ In fact, you are limited to StackOverflow, Amazon and Google Search
SPA is a new sexy❖ No one uses ol’ goo’ ERB
❖ Javascript rules over the web
❖ Web does not work without JS
❖ http://tobyho.com/2010/03/11/how-much-of-the-web-actually/
❖ In fact, you are limited to StackOverflow, Amazon and Google Search
❖ Actually, only paranoids disable JS in 2017
Solutions for APIs❖ Still Rails. Now with API flavor (rails-api). Still Rails.
Still boring. Still overbloated.
Solutions for APIs❖ Still Rails. Now with API flavor (rails-api). Still Rails.
Still boring. Still overbloated.
❖ Sinatra is a new shiny
Solutions for APIs❖ Still Rails. Now with API flavor (rails-api). Still Rails.
Still boring. Still overbloated.
❖ Sinatra is a new shiny OH WAI~~. A little too big
Solutions for APIs❖ Still Rails. Now with API flavor (rails-api). Still Rails.
Still boring. Still overbloated.
❖ Sinatra is a new shiny OH WAI~~. A little too big
❖ Microframeworks like Cuba, NYNY
Solutions for APIs❖ Still Rails. Now with API flavor (rails-api). Still Rails.
Still boring. Still overbloated.
❖ Sinatra is a new shiny OH WAI~~. A little too big
❖ Microframeworks like Cuba, NYNY - too much to write
Solutions for APIs❖ Still Rails. Now with API flavor (rails-api). Still Rails.
Still boring. Still overbloated.
❖ Sinatra is a new shiny OH WAI~~. A little too big
❖ Microframeworks like Cuba, NYNY - too much to write
❖ Roda
Solutions for APIs❖ Still Rails. Now with API flavor (rails-api). Still Rails.
Still boring. Still overbloated.
❖ Sinatra is a new shiny OH WAI~~. A little too big
❖ Microframeworks like Cuba, NYNY - too much to write
❖ Roda - a challenger appears. No one noticed
Solutions for APIs❖ Still Rails. Now with API flavor (rails-api). Still Rails.
Still boring. Still overbloated.
❖ Sinatra is a new shiny OH WAI~~. A little too big
❖ Microframeworks like Cuba, NYNY - too much to write
❖ Roda - a challenger appears. No one noticed
❖ Rack
Solutions for APIs❖ Still Rails. Now with API flavor (rails-api). Still Rails.
Still boring. Still overbloated.
❖ Sinatra is a new shiny OH WAI~~. A little too big
❖ Microframeworks like Cuba, NYNY - too much to write
❖ Roda - a challenger appears. No one noticed
❖ Rack - maybe easier to rewrite the whole stack from scratch?
Solutions for APIs❖ Still Rails. Now with API flavor (rails-api). Still Rails.
Still boring. Still overbloated.
❖ Sinatra is a new shiny OH WAI~~. A little too big
❖ Microframeworks like Cuba, NYNY - too much to write
❖ Roda - a challenger appears. No one noticed
❖ Rack - maybe easier to rewrite the whole stack from scratch? (And end up with buggy unfinished Rails)
WebMachine-ruby❖ Based on Erlang’s web machine
❖ Created by Sean Cribbs
❖ More than 5 years old
❖ Still alive!
WebMachine-ruby❖ Based on Erlang’s web machine
❖ Created by Sean Cribbs
❖ More than 5 years old
❖ Still alive! Last commit - on 30 Jan 2017
WebMachine-ruby❖ Based on Erlang’s web machine
❖ Created by Sean Cribbs
❖ More than 5 years old
❖ Still alive! Last commit - on 30 Jan 2017
❖ 13 issues opened and 80 closed
WebMachine-ruby❖ Based on Erlang’s web machine
❖ Created by Sean Cribbs
❖ More than 5 years old
❖ Still alive! Last commit - on 30 Jan 2017
❖ 13 issues opened and 80 closed
❖ Author works with Erlang, Ruby and Elixir
WebMachine-ruby❖ Based on Erlang’s web machine
❖ Created by Sean Cribbs
❖ More than 5 years old
❖ Still alive! Last commit - on 30 Jan 2017
❖ 13 issues opened and 80 closed
❖ Author works with Erlang, Ruby and Elixir
❖ github://webmachine/webmachine-ruby.git
Fundamental idea❖ Each API resource is a typical state machine
❖ Each request is a flow through this state machine
Fundamental idea❖ Each API resource is a typical state machine
❖ Each request is a flow through this state machine
❖ Most requests are pretty standard
Fundamental idea❖ Each API resource is a typical state machine
❖ Each request is a flow through this state machine
❖ Most requests are pretty standard
❖ Functional behavior is more suiting case for this
Fundamental idea❖ Each API resource is a typical state machine
❖ Each request is a flow through this state machine
❖ Most requests are pretty standard
❖ Functional behavior is more suiting case for this
❖ Define standards and override only needed things
Why state machine?❖ Typical frameworks: request is running by predefined
procedure. They are not your bros
Why state machine?❖ Typical frameworks: request is running by predefined
procedure. They are not your bros
❖ Webmachine determines facts about requests
Why state machine?❖ Typical frameworks: request is running by predefined
procedure. They are not your bros
❖ Webmachine determines facts about requests
❖ Uses finite state machine to determine proper response
Why state machine?❖ Typical frameworks: request is running by predefined
procedure. They are not your bros
❖ Webmachine determines facts about requests
❖ Uses finite state machine to determine proper response
❖ Each fact can easily be tested
Why state machine?❖ Typical frameworks: request is running by predefined
procedure. They are not your bros
❖ Webmachine determines facts about requests
❖ Uses finite state machine to determine proper response
❖ Each fact can easily be tested
❖ Webmachine is your bro
Parsing request❖ Initial request: curl "http://localhost/kudos/1" -H "Accept: application/json" -u test -p test
Parsing request❖ Initial request:
curl "http://localhost/kudos/1" -H "Accept: application/json" -u test -p test
❖ Does route /kudos/:id exist?
Parsing request❖ Initial request:
curl "http://localhost/kudos/1" -H "Accept: application/json" -u test -p test
❖ Does route /kudos/:id exist?
❖ Does resource with ID 1 exist?
Parsing request❖ Initial request:
curl "http://localhost/kudos/1" -H "Accept: application/json" -u test -p test
❖ Does route /kudos/:id exist?
❖ Does resource with ID 1 exist?
❖ Is this user with this password allowed to execute this request on resource?
Parsing request❖ Initial request:
curl "http://localhost/kudos/1" -H "Accept: application/json" -u test -p test
❖ Does route /kudos/:id exist?
❖ Does resource with ID 1 exist?
❖ Is this user with this password allowed to execute this request on resource?
❖ Can this method be called for this resource?
Parsing request❖ Initial request:
curl "http://localhost/kudos/1" -H "Accept: application/json" -u test -p test
❖ Does route /kudos/:id exist?
❖ Does resource with ID 1 exist?
❖ Is this user with this password allowed to execute this request on resource?
❖ Can this method be called for this resource?
❖ Can this resource be rendered with this content type?
Typical resourceclass KudoResource < Webmachine::Resource def allowed_methods ["GET"] end
def content_types_provided [["application/json", :to_json]] end
def resource_exists? kudo # Truthy or falsey end
def to_json kudo.to_json end
private
def kudo @kudo ||= Kudo.find(id) end
def id request.path_info[:id] end end