Your SlideShare is downloading. ×
0
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...
•

•
•

On mediatypes, describes an
anti-pattern implemented in
Ruby on Rails (RoR)
This pattern has unfortunately
made it...
so?
•

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

•

and these can be weighted 8-o

•

We u...
code?
$self->respond_to(
json => { status => $status, json => $response },
text => { status => $status, text => $message },
xml ...
Lessons Learned
•

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

•
...
Upcoming SlideShare
Loading in...5
×

Mojolicious and REST

1,423

Published on

Lessons learning from implementing a RESTful interface using Mojolicious

Published in: Technology
1 Comment
4 Likes
Statistics
Notes
No Downloads
Views
Total Views
1,423
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
9
Comments
1
Likes
4
Embeds 0
No embeds

No notes for slide

Transcript of "Mojolicious and REST"

  1. 1. Mojolicious and REST Building a RESTful interface using Mojolicious By @jonasbn for Nordic Perl Workshop 2013
  2. 2. - $authbridge->route(‘/domain/is_available/:domainname') + $authbridge->route(‘/domain/is_available/#domainname')
  3. 3. • Implementing REST using Mojolicious is easy • very easy • too easy
  4. 4. but!
  5. 5. Rest in Practice Ian Robinson, Jim Webber and Savas Parastatides • On mediatypes, describes an antipattern implemented in Ruby on Rails
  6. 6. • • • 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
  7. 7. so?
  8. 8. • 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
  9. 9. code?
  10. 10. $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) }, );
  11. 11. 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))
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×