http://www.egeniq.com [email protected] @egeniq Code By The Sea November 3, 2015 Ivo Jansch Scenario Driven API Design Or: how to make more usable APIs
Website REST API What if we add even more clients? 14 SQL database THIN BUSINESS LOGIC Controllers Views API client THICK BUSINESS LOGIC Controllers Views Mobile Client?
Scenario Driven Design ‣1. Client analysis ‣Identify client needs ‣Usage scenarios ‣2. Service design ‣Optimal ways to service the client scenarios ‣3. Data modelling ‣Create data model to support the scenario’s ‣Low level and high level concepts ‣4. Interface design ‣REST/HAL etc. interface ‣Versioning, etc. 22
Would this work? ‣Data Driven: ‣GET /movies/:id ‣GET /tickets ‣GET /users/:id ‣Yes it would work ‣but we would easily get stuck with the ’26 api calls’ problem 26
Scenario Driven Design ‣Identify all relevant scenarios: ‣Order a movie ‣Watch a movie ‣See list of my movies ‣Promote content on the home screen ‣See what’s available ‣Like/unlike movies ‣Interactions are platform-specific, scenarios usually aren’t. 27
“Promote content on the home screen” ‣All clients should present, on their home screen, after login: ‣The user’s most recently rented movies ‣User specific recommendations ‣Movie top 20 ‣Featured movies 28
Scenario Driven Design 32 Data Modeling API interface Specific/Generic Clients Service Design 2. Promote content on the home screen 3. Movies, collections, banners 1. ’home’ screen
Scenario Driven Design 33 Data Modeling API interface Specific/Generic Clients Service Design 2. Promote content on the home screen 3. Movies, collections, banners 4. /promoslots/home 1. ’home’ screen
Consider scenario’s at the highest level ‣GET /users/@me/dashboard ‣High Level Scenario ‣Business Logic entirely API side ‣Important: find balance between generic and specific 35
Wise Words ‣Eric S. Raymond: “Smart data and dumb code works a lot better than the other way around” (from: The Cathedral & The Bazaar) ‣In 2015 this means:
A word about tool vendors 41 Data Modeling Interface Design Specific/Generic Clients Service Design db vendor space (commoditised ~ 16 years ago) api tool vendor space (to be commoditised) you