A talk on Scenario Driven API Design, discussing why it's important to think about your APIs and how to avoid the pitfall of creating APIs without any business logic, exposing your raw data models.
http://www.egeniq.com [email protected] @egeniq Zendcon Europe, November 19, 2013 Ivo Jansch Scenario Driven API Design Or: the one with rants about REST Or: the one with Zombies, Coffee, Beer, Elephpants & Bacon
The feature “A dashboard showing the user’s open orders, the order status, one product for each order plus the thumb, and a list of the last 5 sent orders” ! ! Order: 12314 Dispatched Zombie King !9
Very Important REST IS NOT THE PROBLEM. ! YOU ARE. ! (well, at least if you’re the dude that coded that API from the anonymous example) ! (Yes, I know who you are) !19
Scenario Driven Design ‣How is your API going to be used ‣Usage scenarios ! ‣Don’t call it REST (yet) if that’s too scary • HTTP API, JSON API, ... !21
This would work better: ‣/recommendations • or /users/@me/recommendations ‣/promoslots ‣/users/@me/movies ‣/users/@me/movies/liked !27 Interesting concept: Pseudo identifiers compound resources views
Consider the scenario again ‣All clients should present, on their home screen, after login: ‣The user’s 3 most recently rented movies ‣User specific recommendations ‣Movie top 20 ‣Featured movies !28
Ergo: ‣Eric S. Raymond: “Smart data and dumb code works a lot better than the other way around” (from: The Cathedral & The Bazaar) ! ‣In 2013 this means:
Our approach to API designs ‣Research usage scenarios ‣Create resource map ‣Generate rewrite rules ‣Use Zend MVC • without dynamic routing • with lightweight Zend_Application • (With Symfony DI by the way) ‣Validate API !40
Credits ‣ ‘Mom, willie took my teat again’ by Woodlywonderworks - http://www.flickr.com/ photos/wwworks/275200442 ‣ ‘Bacon in the oven’ by Joel Kramer - http://www.flickr.com/photos/ [email protected]/4612278861 ‣ ’3 pounds of goodness’ by Robert S. Donovan - http://www.flickr.com/photos/ [email protected]/7997980826 ‣ ‘Eating the bacon’ by Beatrice Murch - http://www.flickr.com/photos/ [email protected]/5070496311 ‣ ‘David Zuelke’ by Sebastian Bergmann - http://www.flickr.com/photos/ [email protected]/4065324036 ‣ ‘ElePHPants’ by Sebastian Bergmann - http://www.flickr.com/photos/ sebastian_bergmann/2338238596/ ‣ ‘Beer candles from Ghent’ by Guy Renard - http://www.flickr.com/photos/ [email protected]/6933441530 ‣ ‘Nein nein nein das ist verboten’ slide by Davis Zuelke - http:// munich2012.drupal.org/sites/default/files/slides/ drupalconmunich2012_http_rest_0.pdf