SlideShare a Scribd company logo
Mojolicious and REST
Building a RESTful interface using Mojolicious

By @jonasbn for Nordic Perl Workshop 2013
-

$authbridge->route(‘/domain/is_available/:domainname')

+

$authbridge->route(‘/domain/is_available/#domainname')
•

Implementing REST using Mojolicious is easy

•

very easy

•

too easy
but!
Rest in
Practice
Ian Robinson, Jim Webber
and Savas Parastatides
•

On mediatypes, describes an antipattern implemented in Ruby on Rails
•

•
•

On mediatypes, describes an
anti-pattern implemented in
Ruby on Rails (RoR)
This pattern has unfortunately
made it to Mojolicious
and that is to have the mediatype communicated on the URL
so?
•

The recommended practice is to use Accept
headers to communicate media-types

•

and these can be weighted 8-o

•

We use HTTP status codes to communicate state
and status

•

URLs should be used to communicate intent not
formatting

•

For Mojolicious this required some experimenting
code?
$self->respond_to(
json => { status => $status, json => $response },
text => { status => $status, text => $message },
xml => {
status => $status,
text
=> XMLout(
$response,
NoAttr
=> TRUE,
RootName => XML_ROOT,
keyattr => [],
XMLDecl => XML_DECL
)
},
any => {
status => HTTP_UNSUPPORTED_MEDIA_TYPE,
json
=> status_message(HTTP_UNSUPPORTED_MEDIA_TYPE)
},
);
Lessons Learned
•

Mojolicious does the right thing when it comes to the
Accept header and actually does it quite well

•

The anti-pattern supported by Mojolicious can be
avoided

•

Use # instead of : in your routes (see the diff) and it will
work

•

But actually ?format=(json|text|xml) is supported but we
only use it for debugging (and it actually has
precedence (and it is undocumented on our side))

More Related Content

ZIP
Mojolicious
PDF
Mojolicious mvc
KEY
Plack perl superglue for web frameworks and servers
KEY
Psgi Plack Sfpm
PDF
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
PDF
Lightweight Webservices with Sinatra and RestClient
PDF
Plack basics for Perl websites - YAPC::EU 2011
PDF
遇見 Ruby on Rails
Mojolicious
Mojolicious mvc
Plack perl superglue for web frameworks and servers
Psgi Plack Sfpm
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Lightweight Webservices with Sinatra and RestClient
Plack basics for Perl websites - YAPC::EU 2011
遇見 Ruby on Rails

What's hot (20)

PDF
Sinatra Rack And Middleware
KEY
Rails Presentation (Anton Dmitriyev)
PDF
Djangocon 2014 angular + django
PDF
RoR (Ruby on Rails)
PDF
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
PPT
Build Your Own CMS with Apache Sling
PDF
Avoiding Common Pitfalls in Ember.js
PDF
Ruby and Rails by Example (GeekCamp edition)
PDF
Apache Sling - The whys and the hows
PPTX
HTML5 Real-Time and Connectivity
ODP
A Toda Maquina Con Ruby on Rails
PDF
Ugo Cei Presentation
PDF
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
PPTX
Webinar: AngularJS and the WordPress REST API
PDF
FITC - Here Be Dragons: Advanced JavaScript Debugging
PDF
Modern Perl Web Development with Dancer
PDF
Ruby MVC from scratch with Rack
PDF
O que há de novo no Rails 3
PPTX
Jedi Mind Tricks for Git
PDF
Jedi Mind Tricks in Git
Sinatra Rack And Middleware
Rails Presentation (Anton Dmitriyev)
Djangocon 2014 angular + django
RoR (Ruby on Rails)
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Build Your Own CMS with Apache Sling
Avoiding Common Pitfalls in Ember.js
Ruby and Rails by Example (GeekCamp edition)
Apache Sling - The whys and the hows
HTML5 Real-Time and Connectivity
A Toda Maquina Con Ruby on Rails
Ugo Cei Presentation
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Webinar: AngularJS and the WordPress REST API
FITC - Here Be Dragons: Advanced JavaScript Debugging
Modern Perl Web Development with Dancer
Ruby MVC from scratch with Rack
O que há de novo no Rails 3
Jedi Mind Tricks for Git
Jedi Mind Tricks in Git
Ad

Viewers also liked (20)

PDF
Mojolicious, real-time web framework
PDF
Building a MongoDB App with Perl
PDF
MongoDB for Perl Developers
PDF
Making Your Perl REST
PPTX
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
PPT
Stop Making The Web Harder Than It Is; Real-world REST, HATEOAS, and Hypermed...
PDF
Amazon DynamoDB Lessen's Learned by Beginner
PPTX
Employment check
PDF
AuthBridge Newsletter Issue 5- Background Screening is Important Across the H...
PDF
‘‘I love my bones!’’ – self-harm and dangerous eating youth behaviours in Por...
PDF
Test builder
PPT
Linkedinstudentppt
PPT
Linkedinstudentppt
PPTX
NEDMAInno14: The Fundamental Things Still Apply: How to Deal with "Innovation...
PDF
Илья Бирман – Ангстрем
PPT
Using Resources And Evaluation Worksheet
PDF
Illustrations creatives
PPTX
Make It Your Own: Design A Makerspace for ALL WMS 2014 GaETC presentation
PPTX
Source control branching and merging guidelines
Mojolicious, real-time web framework
Building a MongoDB App with Perl
MongoDB for Perl Developers
Making Your Perl REST
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Stop Making The Web Harder Than It Is; Real-world REST, HATEOAS, and Hypermed...
Amazon DynamoDB Lessen's Learned by Beginner
Employment check
AuthBridge Newsletter Issue 5- Background Screening is Important Across the H...
‘‘I love my bones!’’ – self-harm and dangerous eating youth behaviours in Por...
Test builder
Linkedinstudentppt
Linkedinstudentppt
NEDMAInno14: The Fundamental Things Still Apply: How to Deal with "Innovation...
Илья Бирман – Ангстрем
Using Resources And Evaluation Worksheet
Illustrations creatives
Make It Your Own: Design A Makerspace for ALL WMS 2014 GaETC presentation
Source control branching and merging guidelines
Ad

Similar to Mojolicious and REST (20)

PPT
Rails Vs CakePHP
PDF
Úvod do Ruby on Rails
KEY
Ruby On Rails
PPTX
Exploring Ruby on Rails and PostgreSQL
PPTX
Ruby on Rails : First Mile
PDF
Ruby and Rails short motivation
PPTX
Ruby on Rails All Hands Meeting
PPTX
Scaling with swagger
PDF
Ruby Metaprogramming - OSCON 2008
PDF
Rails On Spring
PDF
Workin On The Rails Road
PDF
6 reasons Jubilee could be a Rubyist's new best friend
PPT
Workin ontherailsroad
PPT
WorkinOnTheRailsRoad
PPT
Ruby On Rails
KEY
Ruby on Rails survival guide of an aged Java developer
KEY
Intro to Ruby on Rails
PPTX
Modeling Tricks My Relational Database Never Taught Me
PPTX
Intro to Rails
PDF
Getting Distributed (With Ruby On Rails)
Rails Vs CakePHP
Úvod do Ruby on Rails
Ruby On Rails
Exploring Ruby on Rails and PostgreSQL
Ruby on Rails : First Mile
Ruby and Rails short motivation
Ruby on Rails All Hands Meeting
Scaling with swagger
Ruby Metaprogramming - OSCON 2008
Rails On Spring
Workin On The Rails Road
6 reasons Jubilee could be a Rubyist's new best friend
Workin ontherailsroad
WorkinOnTheRailsRoad
Ruby On Rails
Ruby on Rails survival guide of an aged Java developer
Intro to Ruby on Rails
Modeling Tricks My Relational Database Never Taught Me
Intro to Rails
Getting Distributed (With Ruby On Rails)

More from Jonas Brømsø (11)

PDF
Markdownlint
PDF
Perl-Critic
PDF
Stackato v6
PDF
Stackato v5
PDF
Stackato v4
PDF
Stackato v3
PDF
Stackato v2
PDF
Stackato
PDF
Using Jenkins for Continuous Integration of Perl components OSD2011
PDF
Workflow NPW2010
PDF
Workflow Yapceu2010
Markdownlint
Perl-Critic
Stackato v6
Stackato v5
Stackato v4
Stackato v3
Stackato v2
Stackato
Using Jenkins for Continuous Integration of Perl components OSD2011
Workflow NPW2010
Workflow Yapceu2010

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Modernizing your data center with Dell and AMD
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
KodekX | Application Modernization Development
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Empathic Computing: Creating Shared Understanding
PDF
Electronic commerce courselecture one. Pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Modernizing your data center with Dell and AMD
Diabetes mellitus diagnosis method based random forest with bat algorithm
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
A Presentation on Artificial Intelligence
KodekX | Application Modernization Development
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Understanding_Digital_Forensics_Presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Building Integrated photovoltaic BIPV_UPV.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Empathic Computing: Creating Shared Understanding
Electronic commerce courselecture one. Pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation
Spectral efficient network and resource selection model in 5G networks
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Mojolicious and REST