SlideShare a Scribd company logo
Ruby Meditation #13
Functional web apps with
Webmachine framework
Mikhail Bortnyk, Amoniac OÜ
Who am I
❖ Mikhail Bortnyk
Who am I
❖ Mikhail Bortnyk
❖ github: @vessi
Who am I
❖ Mikhail Bortnyk
❖ github: @vessi
❖ twitter: @mikhailbortnyk
Who am I
❖ Mikhail Bortnyk
❖ github: @vessi
❖ twitter: @mikhailbortnyk
❖ language researcher
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!)
Source code
❖ [Link to presentation online]
Source code
❖ [Link to presentation online]
❖ [Link to source code on GitHub]
Introduction
Typical experience of web developer
CGI Old school is cool! (Bash, C, Perl, some scripting)
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
SPA is a new sexy
❖ No one uses ol’ goo’ ERB
❖ Javascript rules over the web
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
We are outdated
No more MPA applications
Web developers are developing
APIs
APIs for SPAs, for mobile
applications, for another APIs
Solutions for APIs
❖ Still Rails. Now with API flavor (rails-api)
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)
If you can’t create it, steal it
WebMachine-ruby
❖ Based on Erlang’s web machine
WebMachine-ruby
❖ Based on Erlang’s web machine
❖ Created by Sean Cribbs
WebMachine-ruby
❖ Based on Erlang’s web machine
❖ Created by Sean Cribbs
❖ More than 5 years old
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
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.
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
State machine diagram
Request to resource flow
Validation and authorization
Content negotiation
Existence and redirection
Conditional requests
PUT/POST (resource creation)
DELETE (resource deletion)
render body
How it parses your request?
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 resource
class 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
Little coding session
Bonus: request trace
Even more
Lattice: Webmachine on actors
Thank you!
Questions?

More Related Content

What's hot

Mind your lang (for role=drinks at CSUN 2017)
Mind your lang (for role=drinks at CSUN 2017)Mind your lang (for role=drinks at CSUN 2017)
Mind your lang (for role=drinks at CSUN 2017)
Adrian Roselli
 
UCLA HACKU'11
UCLA HACKU'11UCLA HACKU'11
UCLA HACKU'11
Gopal Venkatesan
 
Semantic Web: A web that is not the Web
Semantic Web: A web that is not the WebSemantic Web: A web that is not the Web
Semantic Web: A web that is not the Web
Bruce Esrig
 
Pragmatic REST: recent trends in API design
Pragmatic REST: recent trends in API designPragmatic REST: recent trends in API design
Pragmatic REST: recent trends in API design
Marsh Gardiner
 
DIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest MagicDIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest Magic
Jonathan Klein
 
Selfish Accessibility — WordCamp Europe 2017
Selfish Accessibility — WordCamp Europe 2017Selfish Accessibility — WordCamp Europe 2017
Selfish Accessibility — WordCamp Europe 2017
Adrian Roselli
 
Contributing To Rails By Plugin Gem
Contributing To Rails By Plugin GemContributing To Rails By Plugin Gem
Contributing To Rails By Plugin GemDaniel Lv
 
Web ninja html & css
Web ninja   html & cssWeb ninja   html & css
Web ninja html & cssAlfi Rizka
 
I can has API? A Love Story
I can has API? A Love StoryI can has API? A Love Story
I can has API? A Love StoryCal Henderson
 
Firebug
FirebugFirebug
Firebug
Dave Ross
 
Offline for web - Frontend Dev Conf Minsk 2014
Offline for web - Frontend Dev Conf Minsk 2014Offline for web - Frontend Dev Conf Minsk 2014
Offline for web - Frontend Dev Conf Minsk 2014
Jan Jongboom
 
Abstractions: Fringe Accessibility
Abstractions: Fringe AccessibilityAbstractions: Fringe Accessibility
Abstractions: Fringe Accessibility
Adrian Roselli
 
EscConf - Deep Dive Frontend Optimization
EscConf - Deep Dive Frontend OptimizationEscConf - Deep Dive Frontend Optimization
EscConf - Deep Dive Frontend Optimization
Jonathan Klein
 
Modular Open Source in Java for Now and Later
Modular Open Source in Java for Now and LaterModular Open Source in Java for Now and Later
Modular Open Source in Java for Now and Later
Bob Paulin
 
LAMP Optimization
LAMP OptimizationLAMP Optimization
LAMP OptimizationDave Ross
 
Pragmatic REST APIs
Pragmatic REST APIsPragmatic REST APIs
Pragmatic REST APIs
amesar0
 
Cufon - Javascript Font Replacement
Cufon - Javascript Font ReplacementCufon - Javascript Font Replacement
Cufon - Javascript Font ReplacementDave Ross
 

What's hot (17)

Mind your lang (for role=drinks at CSUN 2017)
Mind your lang (for role=drinks at CSUN 2017)Mind your lang (for role=drinks at CSUN 2017)
Mind your lang (for role=drinks at CSUN 2017)
 
UCLA HACKU'11
UCLA HACKU'11UCLA HACKU'11
UCLA HACKU'11
 
Semantic Web: A web that is not the Web
Semantic Web: A web that is not the WebSemantic Web: A web that is not the Web
Semantic Web: A web that is not the Web
 
Pragmatic REST: recent trends in API design
Pragmatic REST: recent trends in API designPragmatic REST: recent trends in API design
Pragmatic REST: recent trends in API design
 
DIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest MagicDIY Synthetic: Private WebPagetest Magic
DIY Synthetic: Private WebPagetest Magic
 
Selfish Accessibility — WordCamp Europe 2017
Selfish Accessibility — WordCamp Europe 2017Selfish Accessibility — WordCamp Europe 2017
Selfish Accessibility — WordCamp Europe 2017
 
Contributing To Rails By Plugin Gem
Contributing To Rails By Plugin GemContributing To Rails By Plugin Gem
Contributing To Rails By Plugin Gem
 
Web ninja html & css
Web ninja   html & cssWeb ninja   html & css
Web ninja html & css
 
I can has API? A Love Story
I can has API? A Love StoryI can has API? A Love Story
I can has API? A Love Story
 
Firebug
FirebugFirebug
Firebug
 
Offline for web - Frontend Dev Conf Minsk 2014
Offline for web - Frontend Dev Conf Minsk 2014Offline for web - Frontend Dev Conf Minsk 2014
Offline for web - Frontend Dev Conf Minsk 2014
 
Abstractions: Fringe Accessibility
Abstractions: Fringe AccessibilityAbstractions: Fringe Accessibility
Abstractions: Fringe Accessibility
 
EscConf - Deep Dive Frontend Optimization
EscConf - Deep Dive Frontend OptimizationEscConf - Deep Dive Frontend Optimization
EscConf - Deep Dive Frontend Optimization
 
Modular Open Source in Java for Now and Later
Modular Open Source in Java for Now and LaterModular Open Source in Java for Now and Later
Modular Open Source in Java for Now and Later
 
LAMP Optimization
LAMP OptimizationLAMP Optimization
LAMP Optimization
 
Pragmatic REST APIs
Pragmatic REST APIsPragmatic REST APIs
Pragmatic REST APIs
 
Cufon - Javascript Font Replacement
Cufon - Javascript Font ReplacementCufon - Javascript Font Replacement
Cufon - Javascript Font Replacement
 

Similar to Functional Web Apps with WebMachine Framework

Rapid API Development with LoopBack/StrongLoop
Rapid API Development with LoopBack/StrongLoopRapid API Development with LoopBack/StrongLoop
Rapid API Development with LoopBack/StrongLoop
Raymond Camden
 
Windycityrails page performance
Windycityrails page performanceWindycityrails page performance
Windycityrails page performance
John McCaffrey
 
Build your own analytics power tools
Build your own analytics power toolsBuild your own analytics power tools
Build your own analytics power tools
Alban Gérôme
 
Offline of web applications
Offline of web applicationsOffline of web applications
Offline of web applications
FDConf
 
6 reasons Jubilee could be a Rubyist's new best friend
6 reasons Jubilee could be a Rubyist's new best friend6 reasons Jubilee could be a Rubyist's new best friend
6 reasons Jubilee could be a Rubyist's new best friend
Forrest Chang
 
The Power of Open Data
The Power of Open DataThe Power of Open Data
The Power of Open Data
Phil Windley
 
Yahoo Pipes Middleware In The Cloud
Yahoo Pipes Middleware In The CloudYahoo Pipes Middleware In The Cloud
Yahoo Pipes Middleware In The CloudConSanFrancisco123
 
Y Pipes Mashup Camp
Y Pipes Mashup CampY Pipes Mashup Camp
Y Pipes Mashup Camp
Jinho Jung
 
Open Data Semantic Web Community Barn Raising
Open Data Semantic Web Community Barn RaisingOpen Data Semantic Web Community Barn Raising
Open Data Semantic Web Community Barn Raising
Boris Mann
 
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Alexander Lisachenko
 
Creating And Consuming Web Services In Php 5
Creating And Consuming Web Services In Php 5Creating And Consuming Web Services In Php 5
Creating And Consuming Web Services In Php 5Michael Girouard
 
Ruby - The Hard Bits
Ruby - The Hard BitsRuby - The Hard Bits
Ruby - The Hard Bits
Paul Gallagher
 
Understanding APIs.pptx introduction chk
Understanding APIs.pptx introduction chkUnderstanding APIs.pptx introduction chk
Understanding APIs.pptx introduction chk
nooreen nayyar syeda
 
Doodling for-great-success
Doodling for-great-successDoodling for-great-success
Doodling for-great-success
Radamanthus Batnag
 
Concurrent Ruby Application Servers
Concurrent Ruby Application ServersConcurrent Ruby Application Servers
Concurrent Ruby Application ServersLin Jen-Shin
 
REST API Pentester's perspective
REST API Pentester's perspectiveREST API Pentester's perspective
REST API Pentester's perspective
SecuRing
 
Mojolicious
MojoliciousMojolicious
Mojolicious
Marcus Ramberg
 
How we took our server side application to the cloud and liked what we got
How we took our server side application to the cloud and liked what we gotHow we took our server side application to the cloud and liked what we got
How we took our server side application to the cloud and liked what we gotBaruch Sadogursky
 

Similar to Functional Web Apps with WebMachine Framework (20)

Rapid API Development with LoopBack/StrongLoop
Rapid API Development with LoopBack/StrongLoopRapid API Development with LoopBack/StrongLoop
Rapid API Development with LoopBack/StrongLoop
 
Windycityrails page performance
Windycityrails page performanceWindycityrails page performance
Windycityrails page performance
 
Build your own analytics power tools
Build your own analytics power toolsBuild your own analytics power tools
Build your own analytics power tools
 
Offline of web applications
Offline of web applicationsOffline of web applications
Offline of web applications
 
6 reasons Jubilee could be a Rubyist's new best friend
6 reasons Jubilee could be a Rubyist's new best friend6 reasons Jubilee could be a Rubyist's new best friend
6 reasons Jubilee could be a Rubyist's new best friend
 
The Power of Open Data
The Power of Open DataThe Power of Open Data
The Power of Open Data
 
Yahoo Pipes Middleware In The Cloud
Yahoo Pipes Middleware In The CloudYahoo Pipes Middleware In The Cloud
Yahoo Pipes Middleware In The Cloud
 
Y Pipes Mashup Camp
Y Pipes Mashup CampY Pipes Mashup Camp
Y Pipes Mashup Camp
 
Open Data Semantic Web Community Barn Raising
Open Data Semantic Web Community Barn RaisingOpen Data Semantic Web Community Barn Raising
Open Data Semantic Web Community Barn Raising
 
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
 
Os Bowkett
Os BowkettOs Bowkett
Os Bowkett
 
Creating And Consuming Web Services In Php 5
Creating And Consuming Web Services In Php 5Creating And Consuming Web Services In Php 5
Creating And Consuming Web Services In Php 5
 
Ruby - The Hard Bits
Ruby - The Hard BitsRuby - The Hard Bits
Ruby - The Hard Bits
 
Understanding APIs.pptx
Understanding APIs.pptxUnderstanding APIs.pptx
Understanding APIs.pptx
 
Understanding APIs.pptx introduction chk
Understanding APIs.pptx introduction chkUnderstanding APIs.pptx introduction chk
Understanding APIs.pptx introduction chk
 
Doodling for-great-success
Doodling for-great-successDoodling for-great-success
Doodling for-great-success
 
Concurrent Ruby Application Servers
Concurrent Ruby Application ServersConcurrent Ruby Application Servers
Concurrent Ruby Application Servers
 
REST API Pentester's perspective
REST API Pentester's perspectiveREST API Pentester's perspective
REST API Pentester's perspective
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
How we took our server side application to the cloud and liked what we got
How we took our server side application to the cloud and liked what we gotHow we took our server side application to the cloud and liked what we got
How we took our server side application to the cloud and liked what we got
 

More from Amoniac OÜ

Dokku your own heroku 21
Dokku   your own heroku 21Dokku   your own heroku 21
Dokku your own heroku 21
Amoniac OÜ
 
GO in Heterogeneous Language Environments
GO in Heterogeneous Language EnvironmentsGO in Heterogeneous Language Environments
GO in Heterogeneous Language Environments
Amoniac OÜ
 
Cleaners of Caribbean
Cleaners of CaribbeanCleaners of Caribbean
Cleaners of Caribbean
Amoniac OÜ
 
Ruby JIT Compilation
Ruby JIT CompilationRuby JIT Compilation
Ruby JIT Compilation
Amoniac OÜ
 
Ambiguous Sinatra
Ambiguous SinatraAmbiguous Sinatra
Ambiguous Sinatra
Amoniac OÜ
 
Capistrano and SystemD
Capistrano and SystemDCapistrano and SystemD
Capistrano and SystemD
Amoniac OÜ
 
Distributed Cluster in Ruby
Distributed Cluster in RubyDistributed Cluster in Ruby
Distributed Cluster in Ruby
Amoniac OÜ
 
Roda: Putting the Fun Back into Ruby Web Development
Roda: Putting the Fun Back into Ruby Web DevelopmentRoda: Putting the Fun Back into Ruby Web Development
Roda: Putting the Fun Back into Ruby Web Development
Amoniac OÜ
 
Rubymotion: Overview and Ecosystem
Rubymotion: Overview and EcosystemRubymotion: Overview and Ecosystem
Rubymotion: Overview and Ecosystem
Amoniac OÜ
 
Rupher
RupherRupher
Rupher
Amoniac OÜ
 
Different Ways of Integrating React into Rails - Pros and Cons
Different Ways of Integrating React into Rails - Pros and ConsDifferent Ways of Integrating React into Rails - Pros and Cons
Different Ways of Integrating React into Rails - Pros and Cons
Amoniac OÜ
 
Functional Ruby
Functional RubyFunctional Ruby
Functional Ruby
Amoniac OÜ
 
How to Become a Сhef
How to Become a СhefHow to Become a Сhef
How to Become a Сhef
Amoniac OÜ
 
Let's Count Bytes! Launching Ruby in 32K of RAM
Let's Count Bytes! Launching Ruby in 32K of RAMLet's Count Bytes! Launching Ruby in 32K of RAM
Let's Count Bytes! Launching Ruby in 32K of RAM
Amoniac OÜ
 
Deployment tales
Deployment talesDeployment tales
Deployment tales
Amoniac OÜ
 

More from Amoniac OÜ (15)

Dokku your own heroku 21
Dokku   your own heroku 21Dokku   your own heroku 21
Dokku your own heroku 21
 
GO in Heterogeneous Language Environments
GO in Heterogeneous Language EnvironmentsGO in Heterogeneous Language Environments
GO in Heterogeneous Language Environments
 
Cleaners of Caribbean
Cleaners of CaribbeanCleaners of Caribbean
Cleaners of Caribbean
 
Ruby JIT Compilation
Ruby JIT CompilationRuby JIT Compilation
Ruby JIT Compilation
 
Ambiguous Sinatra
Ambiguous SinatraAmbiguous Sinatra
Ambiguous Sinatra
 
Capistrano and SystemD
Capistrano and SystemDCapistrano and SystemD
Capistrano and SystemD
 
Distributed Cluster in Ruby
Distributed Cluster in RubyDistributed Cluster in Ruby
Distributed Cluster in Ruby
 
Roda: Putting the Fun Back into Ruby Web Development
Roda: Putting the Fun Back into Ruby Web DevelopmentRoda: Putting the Fun Back into Ruby Web Development
Roda: Putting the Fun Back into Ruby Web Development
 
Rubymotion: Overview and Ecosystem
Rubymotion: Overview and EcosystemRubymotion: Overview and Ecosystem
Rubymotion: Overview and Ecosystem
 
Rupher
RupherRupher
Rupher
 
Different Ways of Integrating React into Rails - Pros and Cons
Different Ways of Integrating React into Rails - Pros and ConsDifferent Ways of Integrating React into Rails - Pros and Cons
Different Ways of Integrating React into Rails - Pros and Cons
 
Functional Ruby
Functional RubyFunctional Ruby
Functional Ruby
 
How to Become a Сhef
How to Become a СhefHow to Become a Сhef
How to Become a Сhef
 
Let's Count Bytes! Launching Ruby in 32K of RAM
Let's Count Bytes! Launching Ruby in 32K of RAMLet's Count Bytes! Launching Ruby in 32K of RAM
Let's Count Bytes! Launching Ruby in 32K of RAM
 
Deployment tales
Deployment talesDeployment tales
Deployment tales
 

Recently uploaded

Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
QuickwayInfoSystems3
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 

Recently uploaded (20)

Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 

Functional Web Apps with WebMachine Framework

  • 1. Ruby Meditation #13 Functional web apps with Webmachine framework Mikhail Bortnyk, Amoniac OÜ
  • 2. Who am I ❖ Mikhail Bortnyk
  • 3. Who am I ❖ Mikhail Bortnyk ❖ github: @vessi
  • 4. Who am I ❖ Mikhail Bortnyk ❖ github: @vessi ❖ twitter: @mikhailbortnyk
  • 5. Who am I ❖ Mikhail Bortnyk ❖ github: @vessi ❖ twitter: @mikhailbortnyk ❖ language researcher
  • 6. Who am I ❖ Mikhail Bortnyk ❖ github: @vessi ❖ twitter: @mikhailbortnyk ❖ language researcher ❖ co-founder of Kottans community school
  • 7. Who am I ❖ Mikhail Bortnyk ❖ github: @vessi ❖ twitter: @mikhailbortnyk ❖ language researcher ❖ co-founder of Kottans community school ❖ 3rd contributor of mruby/c
  • 8. 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!)
  • 9. Source code ❖ [Link to presentation online]
  • 10. Source code ❖ [Link to presentation online] ❖ [Link to source code on GitHub]
  • 12. Typical experience of web developer CGI Old school is cool! (Bash, C, Perl, some scripting)
  • 13. Typical experience of web developer CGI Old school is cool! (Bash, C, Perl, some scripting) Servlets I know your pain, bro (PHP, Java)
  • 14. 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)
  • 15.
  • 16. SPA is a new sexy ❖ No one uses ol’ goo’ ERB
  • 17. SPA is a new sexy ❖ No one uses ol’ goo’ ERB ❖ Javascript rules over the web
  • 18. SPA is a new sexy ❖ No one uses ol’ goo’ ERB ❖ Javascript rules over the web ❖ Web does not work without JS
  • 19. 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/
  • 20. 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
  • 21. 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
  • 23. No more MPA applications
  • 24. Web developers are developing APIs
  • 25. APIs for SPAs, for mobile applications, for another APIs
  • 26. Solutions for APIs ❖ Still Rails. Now with API flavor (rails-api)
  • 27. Solutions for APIs ❖ Still Rails. Now with API flavor (rails-api). Still Rails. Still boring. Still overbloated.
  • 28. Solutions for APIs ❖ Still Rails. Now with API flavor (rails-api). Still Rails. Still boring. Still overbloated. ❖ Sinatra is a new shiny
  • 29. 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
  • 30. 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
  • 31. 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
  • 32. 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
  • 33. 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
  • 34. 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
  • 35. 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?
  • 36. 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)
  • 37. If you can’t create it, steal it
  • 38. WebMachine-ruby ❖ Based on Erlang’s web machine
  • 39. WebMachine-ruby ❖ Based on Erlang’s web machine ❖ Created by Sean Cribbs
  • 40. WebMachine-ruby ❖ Based on Erlang’s web machine ❖ Created by Sean Cribbs ❖ More than 5 years old
  • 41. WebMachine-ruby ❖ Based on Erlang’s web machine ❖ Created by Sean Cribbs ❖ More than 5 years old ❖ Still alive!
  • 42. 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
  • 43. 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
  • 44. 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
  • 45. 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
  • 46. Fundamental idea ❖ Each API resource is a typical state machine
  • 47. Fundamental idea ❖ Each API resource is a typical state machine ❖ Each request is a flow through this state machine
  • 48. Fundamental idea ❖ Each API resource is a typical state machine ❖ Each request is a flow through this state machine ❖ Most requests are pretty standard
  • 49. 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
  • 50. 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
  • 51. Why state machine? ❖ Typical frameworks: request is running by predefined procedure.
  • 52. Why state machine? ❖ Typical frameworks: request is running by predefined procedure. They are not your bros
  • 53. Why state machine? ❖ Typical frameworks: request is running by predefined procedure. They are not your bros ❖ Webmachine determines facts about requests
  • 54. 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
  • 55. 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
  • 56. 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
  • 58.
  • 67. How it parses your request?
  • 68. Parsing request ❖ Initial request: 
 curl "http://localhost/kudos/1" -H "Accept: application/json" -u test -p test
  • 69. Parsing request ❖ Initial request: 
 curl "http://localhost/kudos/1" -H "Accept: application/json" -u test -p test ❖ Does route /kudos/:id exist?
  • 70. 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?
  • 71. 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?
  • 72. 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?
  • 73. 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?
  • 74. Typical resource class 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