SlideShare uma empresa Scribd logo
1 de 123
1
Designing and Implementing Hypermedia APIs
QCon New York 2013
 Mike Amundsen,
Principal API Architect
Layer 7 Techologies
@mamund
#HyperQCon
2
Mike Amundsen
 Author, Web Architect, Presenter
 Principal API Architect
 Building Hypermedia APIs with HTML5 and Node
 RESTful Web APIs (Richardson, Amundsen, Ruby)
3
Agenda
 Hypermedia – the Short Story (15:00)
 Designing Hypermedia APIs (10:00 )
 Hack a Hypermedia API (30:00)
 Implementing Hypermedia Servers (10 :00)
 Hack a Hypermedia Server (45:00)
 Building Hypermedia Clients (10:00)
 Hack a Hypermedia Client (45:00)
 Now What? (15:00)
4
Reminders
 Bells & Whistles Off
 Feel free to stretch, move about as needed
 Ask Questions
 Enjoy the Session
5
HYPERMEDIA –
THE SHORT STORY
6
Atlas holds the weight of the world on his shoulders…
7
On the Shoulders of Giants
8
Vannevar Bush
 Memex, 1945
 Key project leader on the Manhattan Project to build the first nuclear
bomb.
 “ A memex …is an enlarged intimate supplement to … memory.”
 “With one item in its grasp, [the mind] snaps instantly to the next that is
suggested by the association of thoughts, in accordance with some
intricate web of trails carried by the cells of the brain.”
9
Douglas Engelbart
 Computer mouse, 1965
 Key to creating the ARPANET while at Stanford Research, Institue (SRI).
 “Augmenting Human Intellect”, 1962
 “[A] new and systematic approach to improving the intellectual effectiveness of
the individual human being … One of the tools that shows the greatest
immediate promise is the computer.”
10
Ted Nelson
 Hypertext, 1963
 Identified and popularized early “cyber-culture” in 1979 book “Computer
Lib/Machine Dreams”
 “If computers are the wave of the future, displays are the surfboards.”
11
James J. Gibson
 “The Ecological Approach to Visual Perception” (1986)
 Coined the term “affordance”
 Environments provide niches of appropriate affordances
 Animals survive/thrive when they can exploit the affordances in their niche
“An affordance is a quality of an object, or an environment, which allows an
individual to perform an action.”
12
Donald Norman
 The Design of Everyday Things, 1988
 Action Lifecycle, Seven Stages of Action
 “In the world” and “In the head”
 “Simplification is as much in the mind as it is in the device.”
 “Design is really an act of communication.”
13
Tim Berners-Lee
 Tim Berners-Lee @ CERN 1980
 ENQUIRE in 1984 (hypertext database)
 Information Mgmt: A Proposal to CERN in 1989
 HTTP (1992), HTML (1993), RDF (2004)
 “A way to link and access information of various kinds as a web of nodes in which the
user can browse at will.”
14
Roy T. Fielding
 Architectural Styles and the
Design of Network-based Software Architectures, 2000
 Created “REST”
 Key in the startup and operation of the “Apache Foundation”
 Representations and Hypermedia
 “A resource is not the thing that is transferred across the wire or picked up off the
disk or seen from afar while walking your dog. Each of those is only a representation.
Do I think of a different identifier every time I see my dog, or do I simply think of my
dog as one identity and experience many representations of that identity over time
(and on into memory and imagination)?
15
On the Shoulders of Giants
16
Hypermedia Factors
17
H-Factors
Analyzing Media Types
18
H-Factors
Analyzing Media Types
19
H-Factors
Analyzing Media Types
20
H-Factors
 There are five LINK Factors
(LO, LE, LT, LI, LN)
 There are four CONTROL Factors
(CR, CU, CM, CL)
21
H-Factors
 There are five LINK Factors
(LO, LE, LT, LI, LN)
 There are four CONTROL Factors
(CR, CU, CM, CL)
22
H-Factors
Linking
Outbound Links (LO)
23
H-Factors
Linking
Outbound Links (LO)
Embedded Links (LE)
24
H-Factors
Linking
Outbound Links (LO)
Embedded Links (LE)
Templated Links (LT)
25
H-Factors
Linking
Outbound Links (LO)
Embedded Links (LE)
Templated Links (LT)
Idempotent Links (LI)
26
H-Factors
Linking
Outbound Links (LO)
Embedded Links (LE)
Templated Links (LT)
Idempotent Links (LI)
Non-Idempotent Links (LN)
27
H-Factors
 There are five LINK Factors
(LO, LE, LT, LI, LN)
 There are four CONTROL Factors
(CR, CU, CM, CL)
28
H-Factors
Control
Request Controls (CR)
29
H-Factors
Control
Request Controls (CR)
Update Controls (CU)
30
H-Factors
Control
Request Controls (CR)
Update Controls (CU)
Method Controls (CM)
31
H-Factors
Control
Request Controls (CR)
Update Controls (CU)
Method Controls (CM)
Link Controls (CL)
32
H-Factors
 A collection of H-Factors is called a Hypermedia Type
 By identifying H-Factors, you discover the “Hypermedia signature” of media type.
33
Three Pillars of Hypermedia Design
34
35
Three Pillars of Hypermedia Design
 Structure Semantics (XML, JSON, YAML, etc.)
 Protocol Semantics (HTTP, WS, FTP, etc.)
 Application Domain Semantics (students, courseName, scheduleId, etc.)
 All Web apps MUST support these somehow. What’s not in the
message, is in the source code instead.
36
Three Pillars of Hypermedia Design
Structure Semantics
 How you communicate the layout of the response
 Simple structures:
- text/csv
- application/xml
- application/json
 Advanced structures
- text/html
- application/atom+xml
- application/vnd.hal+json
- application/vnd.collection+json
37
Three Pillars of Hypermedia Design
Protocol Semantics
 How you communicate the possible actions in the response
 Simple actions:
- HTML.A
- HTML.IMG
- HTML.LINK
 Advanced actions:
- HTML.FORM@get
- HTML.FORM@post
- ATOM.LINK@edit
- collection.queries.link@data[]
38
Three Pillars of Hypermedia Design
Domain Semantics
 How you communicate the domain-specific details in the response
 Simple domain-specifics:
- MAZE: collection, cell
- VOICEXML: assign, transfer, disconnect,
- ATOM: feed, entry, content
 Advanced domain-specifics
- HTML: @id, @name, @class, @rel
- CJ: @id, @name, @value, @href
- HAL: @rel, @name
39
Three Pillars of Hypermedia Design
On the Web, media types don’t define a solution,
they describe a problem domain
40
Three Pillars of Hypermedia Design
The more descriptive the media type,
the easier it is to talk about the problem.
41
DESIGNING HYPERMEDIA APIS
42
Designing Hypermedia APIs
Let’s describe the Class Scheduling domain…
43
Designing Hypermedia APIs
Let’s describe the Class Scheduling domain…
and let’s keep it real simple today.
44
application/vnd.apiacademy-scheduling+xml
45
Domain
 Eleven data elements:
- courseCapacity,
courseDescription,
courseId, courseName,
scheduleId, scheduleSlot,
studentId, studentName,
studentStanding,
teacherId, teacherName
 Eight actions:
- add, update, remove,
read, list, filter, assign,
unassign
 Five identifiers:
- home, course, student,
teacher, schedule
46
Designing Hypermedia APIs
Let’s map the actions to (at least) one Web protocol…
47
Designing Hypermedia APIs
Let’s map the actions to (at least) one Web protocol…
We could use HTTP, WebSockets, XMPP…
48
Designing Hypermedia APIs
Let’s map the actions to (at least) one Web protocol…
We could use HTTP, WebSockets, XMPP…
But, of course, we’ll use HTTP today.
49
Protocol
 Map eight actions:
- add, update, remove,
read, list, filter,
assign, unassign
 To four HTTP methods:
- GET, POST,
PUT, DELETE.
50
Designing Hypermedia APIs
Let’s document the possible data elements
for each action, too.
51
Data elements with actions…
52
Designing Hypermedia APIs
Finally, let’s design a single message
that can carry all that information…
53
Structure
 Nine Elements
- root, actions, link, list,
item, template, display,
data, error
 Six Attributes
- href, name, action,
prompt, value, embed
 Four Data Types
- ID, URI, TEXT,
BOOLEAN
54
Designing Hypermedia APIs
Note we covered the three key aspects
to each message design…
55
Designing Hypermedia APIs
Note we covered the three key aspects
to each message design…
Structure
56
Designing Hypermedia APIs
Note we covered the three key aspects
to each message design…
Structure
Protocol
57
Designing Hypermedia APIs
Note we covered the three key aspects
to each message design…
Structure
Protocol
Domain
58
Now let’s see some examples…
59
60
Let’s Design a Hypermedia API!
61
IMPLEMENTING HYPERMEDIA
SERVERS
62
Implementing Hypermedia Servers
 Components
- Storage
- Object Model/Processing
 Connectors
- Representation
- Routing/Request Handling
63
Component != Connector
64
Component
Database
File System
Message Queue
Transaction Manager
Source Code
65
Component == Private
66
67
Connector
Web Server
Browser Agent
Proxy Server
Shared Cache
68
Connector == Public
69
70
Client Server
Connectors
Components
The Web
71
Representation Layer
72
Representation Layer
 Representation happens in the Connector
 HTTP supports content negotiation
- Accept
- Content-Type
 Differing clients (user-agents) === differing representations
- Desktop
- Browser
- Tablet
- Smartphone
 Be prepared to support multiple representations
73
Implementing Hypermedia Servers
 Storage
 Handles direct access to stored content (if any)
 Database (MySQL, SQLServer, Oracle, CouchDB, Mongo, etc.)
 File system (Local File I/O)
 External Service (Salesforce, Amazon, Azure, etc.)
 In-Memory (memcacheD, etc.)
 Advice for this event:
- Keep it simple
- Use in-memory array for starter, add perm storage later
- Use existing APIs (see listing today)
74
Implementing Hypermedia Servers
 Components
 Handles business rules and any processing/computing, etc.
 Validate data/objects
 Create any defaults or related data/objects
 Enforce data integrity on writes
 Enforce ACLs on reads/writes (skip for today)
 Advice for this event:
- Keep it simple
- Consider read-only for today
- Use existing APIs (see listing today)
75
Implementing Hypermedia Servers
 Representation
 Handles converting internal objects into external media type
 *NOT* a serializer
 Convert object graph into list/items
 Include protocol affordances (links & forms)
 Maps domain-specifics to appropriate elements/attributes/properties
 Advice for this event:
- Keep it simple
- Consider using an existing hypermedia type
- Use existing APIs (see listing today)
76
Implementing Hypermedia Servers
 Routing
 Handles incoming requests, routes to appropriate method/handler
 Thin veneer behind API
 NOT a direct wrapper for components
 Converts request URL parts into arguments
 Usually handles call to representation service for responses
 MAY handle caching directives (skip for today)
 Advice for this event:
- Keep it simple
- Consider a very simple URL routing pattern (/{thing}/{id})
- Use existing APIs (see listing today)
77
Let’s Build a Hypermedia Server!
78
Summary : Implementing Hypermedia Servers
 Components
- Storage (DB, FileSys, external)
- Object Model/Processing (objects, business rules)
 Connectors
- Representation (convert object graph into media type)
- Routing/Request Handling (convert URLs into args & route)
79
BUILDING HYPERMEDIA
CLIENTS
80
Building Hypermedia Clients
 Hypermedia clients for humans
 Hypermedia clients for machines
81
Hypermedia for Humans
82
What is a Hypermedia for Humans client?
A client that is able to
determine possible protocol-level choices at runtime
using only the links and forms in the message itself as a guide.
83
Some things to keep in mind…
Hypermedia clients are based on the “Action Lifecycle”
84
Some things to keep in mind…
http://en.wikipedia.org/wiki/Human_action_cycle
85
Some things to keep in mind…
Oh!, I almost forgot…
86
Hypermedia clients
Typically hypermedia clients have almost no long-term memory.
87
Hypermedia clients
Typically hypermedia clients have almost no long-term memory.
Hypermedia clients’ memories last for a single request/response cycle.
88
Hypermedia clients
Typically hypermedia clients have almost no long-term memory.
Hypermedia clients’ memories last for a single request/response cycle.
Clients MAY save a past response, parse it, store it, and recall it later.
89
Faithful Hypermedia Clients (FHCs)
 FHCs simply pass along whatever the server returns; usually to a human.
 FHCs MAY make some decisions on how to display the returned representation
 FHCs only need a starting URL and a (human) driver.
90
Guide for implementing an FHC
 Process the structure semantics in order to render view
 Process the protocol semantics in order to support available transitions
 Process the domain semantics in order to inform human of choices & results.
91
Process the structure semantics
92
Process the structure semantics
93
Process the structure semantics
94
Process protocol semantics
95
Process protocol semantics
96
Process protocol semantics
97
Process domain semantics
98
Process domain semantics
99
Summary for the Class Schedule FHC
 Structure Semantics
- Take advantage of client-side XSLT
- Build XSL processor for vnd.apiacademy-scheduling+xml
- 120 lines of XSLT
 Protocol Semantics
- Take advantage of XmlHttpRequest
- Provide a single JS file that “understands” vnd.apiacademy-scheduling+xml
- 130 lines of JS
 Domain Semantics
- Use CSS to hide/show things for humans (.id, .dateCreated)
- 130 lines of CSS
100
Advantages of hypermedia clients for humans
 Flexibility to support a wide range of non-breaking domain-level changes
- Adding new display & input fields
- Adding new resources/pages
- Adding new link and form options (not new protocol options)
- Changes in access control rules is “automatic” (No access? No controls!)
 Ability to separate “parsing” from “display”
- Most hypermedia types keep clear separation
between processing and display
- Can make it easier to handle negotiations
between server devs and UI devs
 Ability to customize engines for devices
- Same hypermedia message can be handled
differently on each device, when applicable
- Increased freedom for UI devs
101
Drawbacks of hypermedia clients for humans
 SoC can mean extra work for clients
- Need to keep structure, protocol, domain clearly separated
 Possibility of changes in server can limit UI options
- UI devs must plan for change (even before it happens)
 Anything short of FHC risks client adaptability
- If client determines what to display, new fields will not appear.
- If client determines what transitions to support
and in what order they appear, changes (add/
move forms & links) may break the client.
 If the message format is unstable (breaking
changes occurring), FHCs have no real
advantage over one-off client coding.
102
Hypermedia for Machines
Hypermedia for Machines
103
What is a hypermedia machine client?
A client that is able to
process responses,
locate protocol actions, and
make domain-level choices at runtime
using only the links and forms in the message itself as a guide.
104
What is a hypermedia machine client?
A client that is able to
process responses,
locate protocol actions, and
make domain-level choices at runtime
using only the links and forms in the message itself as a guide.
105
Agent Hypermedia Clients (AHCs)
 AHCs can process all three levels of messages:
- Structure
- Protocol
- Domain
 AHCs MUST be able to make decisions on their own
 AHCs need only a starting URL
 http://xkcd.com/695/
106
Guide for implementing an AHC
 Process the structure semantics in order to know what’s “there”
 Process the protocol semantics in order to know what’s possible
 Process the domain semantics in order to make an informed choice
 The machine is in charge of the complete “Action Lifecycle”
107
Maze+XML Media Type
108
Maze+XML FHC
109
The Maze+XML AHC
110
“Teach” AHC about mazes
111
Process the structure semantics
112
Process the protocol semantics
113
Process the domain semantics
114
Summary for Maze+XML AHC
 Structure Semantics
- XML DOM Parser + recognizing five elements (maze, collection, item,cell, link)
 Protocol Semantics
- Support maze:link (H-factor=LO, HTTP.GET)
 Domain Semantics
- Understand “wall-following” and choose between “start”, “north”, “south”, “east”,
west”, and “exit”
 150 lines of NodeJS code
115
Advantages of hypermedia clients for machines
 Ability to hand off tedious work to “smart” machine
 Using “generic” media types makes it possible to use the same client code for
several different tasks/projects
 Coding new tasks gets faster over time since the baseline code already exists
 Simple modifications in the server (order to items in message) don’t break clients
116
Drawbacks of hypermedia clients for machines
 Making machines “smart” takes time, esp. for non-trivial tasks
 Some changes in message can break clients (missing transitions, new fields, etc.)
 Some unsafe operations (POST/PUT/DELETE) may need human intervention
anyway.
 Not many “machine-friendly” hypermedia types yet.
117
Let’s Build a Hypermedia Client!
118
Summary : Building Hypermedia Clients
 Hypermedia clients for humans (FHC)
- A client that is able to determine possible protocol-level choices at runtime
using only the links and forms in the message itself as a guide.
 Hypermedia clients for machines (AHC)
- A client that is able to process responses, locate protocol actions, and make
domain-level choices at runtime using only the links and forms in the
message itself as a guide.
 Hypermedia clients are based on the “Action Lifecycle”
 Hypermedia clients’ memories usually last for a single request/response cycle.
119
NOW WHAT?
120
Now What?
 Hypermedia goes back more than ½ a century
 Remember the H-Factors (LO, LE, LT, LI, LN, CR, CU, CM, CL)
 Always solve for the Three Pillars (Structure, Protocol, Domain)
 Servers have:
- Components (Storage & Processing)
- Connectors (Routing & Representation)
 Clients have:
- No long-term memory
- Support for Action Lifecycle
- FHCs (for humans)
- ACHs (for machines)
121
Let’s Grow the Hypermedia Web!
122
Available Server Projects
 YouTypeItWePostIt (:8080/api/)
- https://github.com/mamund/rwa
 Maze+XML (:8181)
- https://github.com/mamund/rwa
 Class-Schedule (:8282)
- https://github.com/apiacademy/class-scheduling
 To-Do-REST (:8383)
- https://github.com/mamund/to-do-rest
123
Designing and Implementing Hypermedia APIs
QCon New York 2013
 Mike Amundsen,
Principal API Architect
Layer 7 Techologies
@mamund
#HyperQCon

Mais conteúdo relacionado

Mais procurados

Tutorial archi cad 7.0
Tutorial archi cad 7.0Tutorial archi cad 7.0
Tutorial archi cad 7.0
imaduddin91
 
UX白書サマリー資料20111015
UX白書サマリー資料20111015UX白書サマリー資料20111015
UX白書サマリー資料20111015
hcdvalue
 

Mais procurados (12)

Tutorial archi cad 7.0
Tutorial archi cad 7.0Tutorial archi cad 7.0
Tutorial archi cad 7.0
 
誰も教えてくれないペルソナのひみつ 〜ペルソナの上手な使いかた〜
誰も教えてくれないペルソナのひみつ 〜ペルソナの上手な使いかた〜誰も教えてくれないペルソナのひみつ 〜ペルソナの上手な使いかた〜
誰も教えてくれないペルソナのひみつ 〜ペルソナの上手な使いかた〜
 
明日から使えるグラフィックレコーディング入門 How Graphic Recording
明日から使えるグラフィックレコーディング入門 How Graphic Recording明日から使えるグラフィックレコーディング入門 How Graphic Recording
明日から使えるグラフィックレコーディング入門 How Graphic Recording
 
UX白書サマリー資料20111015
UX白書サマリー資料20111015UX白書サマリー資料20111015
UX白書サマリー資料20111015
 
The Double Diamond Model of Product Definition and Execution
The Double Diamond Model of Product Definition and ExecutionThe Double Diamond Model of Product Definition and Execution
The Double Diamond Model of Product Definition and Execution
 
SIMPLE ISO 19650 TEMPLATES (BILT VIRTUAL PRESENTATION)
SIMPLE ISO 19650 TEMPLATES (BILT VIRTUAL PRESENTATION)SIMPLE ISO 19650 TEMPLATES (BILT VIRTUAL PRESENTATION)
SIMPLE ISO 19650 TEMPLATES (BILT VIRTUAL PRESENTATION)
 
Hs2
Hs2Hs2
Hs2
 
[#pmconf2020] 自己流から一流プロダクトマネージャーになるために学ぶべきこと
[#pmconf2020] 自己流から一流プロダクトマネージャーになるために学ぶべきこと[#pmconf2020] 自己流から一流プロダクトマネージャーになるために学ぶべきこと
[#pmconf2020] 自己流から一流プロダクトマネージャーになるために学ぶべきこと
 
IT推進に必要なUXを学ぶ ~UXを意識して真の業務改善・真のDXを目指す~
IT推進に必要なUXを学ぶ ~UXを意識して真の業務改善・真のDXを目指す~IT推進に必要なUXを学ぶ ~UXを意識して真の業務改善・真のDXを目指す~
IT推進に必要なUXを学ぶ ~UXを意識して真の業務改善・真のDXを目指す~
 
UI設計の土台になる考え方-インテリジェントネット社内勉強会
UI設計の土台になる考え方-インテリジェントネット社内勉強会UI設計の土台になる考え方-インテリジェントネット社内勉強会
UI設計の土台になる考え方-インテリジェントネット社内勉強会
 
もしプロダクトマネージャー・プロダクトチームにUXリサーチのメンターがついたら <レクイエム>
もしプロダクトマネージャー・プロダクトチームにUXリサーチのメンターがついたら <レクイエム>もしプロダクトマネージャー・プロダクトチームにUXリサーチのメンターがついたら <レクイエム>
もしプロダクトマネージャー・プロダクトチームにUXリサーチのメンターがついたら <レクイエム>
 
Visual Design
Visual DesignVisual Design
Visual Design
 

Destaque

Medroxyprogesterone Acetate in Glial Tumor Treatment. Our Experimental Results
Medroxyprogesterone Acetate in Glial Tumor Treatment. Our Experimental Results Medroxyprogesterone Acetate in Glial Tumor Treatment. Our Experimental Results
Medroxyprogesterone Acetate in Glial Tumor Treatment. Our Experimental Results
NeuroAcademy
 
PRIMEROS AUXILIOS
PRIMEROS AUXILIOSPRIMEROS AUXILIOS
PRIMEROS AUXILIOS
elbamarina
 
Daum APIs: A to Z - API Meetup 2014
Daum APIs: A to Z  - API Meetup 2014Daum APIs: A to Z  - API Meetup 2014
Daum APIs: A to Z - API Meetup 2014
Channy Yun
 
Tema27 estado actual de las investigaciones sobre control de enfermedades tra...
Tema27 estado actual de las investigaciones sobre control de enfermedades tra...Tema27 estado actual de las investigaciones sobre control de enfermedades tra...
Tema27 estado actual de las investigaciones sobre control de enfermedades tra...
Saam Ha
 
Clasificasion De Enfermedades (x Sosa Y Arce)
Clasificasion De Enfermedades (x Sosa Y Arce)Clasificasion De Enfermedades (x Sosa Y Arce)
Clasificasion De Enfermedades (x Sosa Y Arce)
media14promse
 

Destaque (18)

Horno AEG BE3013521M
Horno AEG BE3013521MHorno AEG BE3013521M
Horno AEG BE3013521M
 
Puskesmas
PuskesmasPuskesmas
Puskesmas
 
Mónica sánchez
Mónica sánchezMónica sánchez
Mónica sánchez
 
Medroxyprogesterone Acetate in Glial Tumor Treatment. Our Experimental Results
Medroxyprogesterone Acetate in Glial Tumor Treatment. Our Experimental Results Medroxyprogesterone Acetate in Glial Tumor Treatment. Our Experimental Results
Medroxyprogesterone Acetate in Glial Tumor Treatment. Our Experimental Results
 
Modelo acreditacion
Modelo acreditacionModelo acreditacion
Modelo acreditacion
 
Secure and Govern Integration between the Enterprise & the Cloud
Secure and Govern Integration between the Enterprise & the CloudSecure and Govern Integration between the Enterprise & the Cloud
Secure and Govern Integration between the Enterprise & the Cloud
 
CIOB
CIOBCIOB
CIOB
 
Lavavajillas Aeg F55512M0
Lavavajillas Aeg F55512M0Lavavajillas Aeg F55512M0
Lavavajillas Aeg F55512M0
 
PRIMEROS AUXILIOS
PRIMEROS AUXILIOSPRIMEROS AUXILIOS
PRIMEROS AUXILIOS
 
Reusable APIs
Reusable APIsReusable APIs
Reusable APIs
 
APIs for biz dev 2.0 - Which business model to win in the API Economy?
APIs for biz dev 2.0 - Which business model to win in the API Economy?APIs for biz dev 2.0 - Which business model to win in the API Economy?
APIs for biz dev 2.0 - Which business model to win in the API Economy?
 
Chapter 27
Chapter 27Chapter 27
Chapter 27
 
Introducing Swagger
Introducing SwaggerIntroducing Swagger
Introducing Swagger
 
RESTful Web APIs – Mike Amundsen, Principal API Architect, Layer 7
RESTful Web APIs – Mike Amundsen, Principal API Architect, Layer 7RESTful Web APIs – Mike Amundsen, Principal API Architect, Layer 7
RESTful Web APIs – Mike Amundsen, Principal API Architect, Layer 7
 
Daum APIs: A to Z - API Meetup 2014
Daum APIs: A to Z  - API Meetup 2014Daum APIs: A to Z  - API Meetup 2014
Daum APIs: A to Z - API Meetup 2014
 
Tema27 estado actual de las investigaciones sobre control de enfermedades tra...
Tema27 estado actual de las investigaciones sobre control de enfermedades tra...Tema27 estado actual de las investigaciones sobre control de enfermedades tra...
Tema27 estado actual de las investigaciones sobre control de enfermedades tra...
 
Clasificasion De Enfermedades (x Sosa Y Arce)
Clasificasion De Enfermedades (x Sosa Y Arce)Clasificasion De Enfermedades (x Sosa Y Arce)
Clasificasion De Enfermedades (x Sosa Y Arce)
 
API Security and Management Best Practices
API Security and Management Best PracticesAPI Security and Management Best Practices
API Security and Management Best Practices
 

Semelhante a Designing & Implementing Hypermedia APIs – Mike Amundsen, Principal API Architect, Layer 7

Semantic Web 2.0
Semantic Web 2.0Semantic Web 2.0
Semantic Web 2.0
hchen1
 
The scripting library: Combining data and information in the library
The scripting library: Combining data and information in the libraryThe scripting library: Combining data and information in the library
The scripting library: Combining data and information in the library
Bonaria Biancu
 
Big Data Management Analytics And Management Essay
Big Data Management Analytics And Management EssayBig Data Management Analytics And Management Essay
Big Data Management Analytics And Management Essay
Amy Alexander
 

Semelhante a Designing & Implementing Hypermedia APIs – Mike Amundsen, Principal API Architect, Layer 7 (20)

Implementing Hypermedia Clients: It's Not Rocket Science – Mike Amundsen, Pri...
Implementing Hypermedia Clients: It's Not Rocket Science – Mike Amundsen, Pri...Implementing Hypermedia Clients: It's Not Rocket Science – Mike Amundsen, Pri...
Implementing Hypermedia Clients: It's Not Rocket Science – Mike Amundsen, Pri...
 
The Costs and Benefits of Building Hypermedia APIs (with Node.js)
The Costs and Benefits of Building Hypermedia APIs (with Node.js)The Costs and Benefits of Building Hypermedia APIs (with Node.js)
The Costs and Benefits of Building Hypermedia APIs (with Node.js)
 
Web Technology Trends (early 2009)
Web Technology Trends (early 2009)Web Technology Trends (early 2009)
Web Technology Trends (early 2009)
 
Web 2.0 Overview
Web 2.0 OverviewWeb 2.0 Overview
Web 2.0 Overview
 
Students of Navgujarat College of Computer Applications, Ahmedabad felt excit...
Students of Navgujarat College of Computer Applications, Ahmedabad felt excit...Students of Navgujarat College of Computer Applications, Ahmedabad felt excit...
Students of Navgujarat College of Computer Applications, Ahmedabad felt excit...
 
Semantic Web 2.0
Semantic Web 2.0Semantic Web 2.0
Semantic Web 2.0
 
-overview of res tful architecture-2
-overview of res tful architecture-2-overview of res tful architecture-2
-overview of res tful architecture-2
 
Hadoop and Beyond
Hadoop and BeyondHadoop and Beyond
Hadoop and Beyond
 
Semantic Wikis - Social Semantic Web in Action
Semantic Wikis - Social Semantic Web in ActionSemantic Wikis - Social Semantic Web in Action
Semantic Wikis - Social Semantic Web in Action
 
Hypertext2007 Carole Goble Keynote - "The Return of the Prodigal Web"
Hypertext2007 Carole Goble Keynote - "The Return of the Prodigal Web"Hypertext2007 Carole Goble Keynote - "The Return of the Prodigal Web"
Hypertext2007 Carole Goble Keynote - "The Return of the Prodigal Web"
 
Social Learning and Knowledge Sharing Technologies Lecture Slides about Socia...
Social Learning and Knowledge Sharing Technologies Lecture Slides about Socia...Social Learning and Knowledge Sharing Technologies Lecture Slides about Socia...
Social Learning and Knowledge Sharing Technologies Lecture Slides about Socia...
 
Busy Architects Guide to Modern Web Architecture in 2014
Busy Architects Guide to  Modern Web Architecture in 2014Busy Architects Guide to  Modern Web Architecture in 2014
Busy Architects Guide to Modern Web Architecture in 2014
 
The scripting library: Combining data and information in the library
The scripting library: Combining data and information in the libraryThe scripting library: Combining data and information in the library
The scripting library: Combining data and information in the library
 
Developing applications with Kurento
Developing applications with KurentoDeveloping applications with Kurento
Developing applications with Kurento
 
A Semantic Multimedia Web (Part 3)
A Semantic Multimedia Web (Part 3)A Semantic Multimedia Web (Part 3)
A Semantic Multimedia Web (Part 3)
 
Web Topics
Web TopicsWeb Topics
Web Topics
 
Big Data Management Analytics And Management Essay
Big Data Management Analytics And Management EssayBig Data Management Analytics And Management Essay
Big Data Management Analytics And Management Essay
 
Be My API How to Implement an API Strategy Everyone will Love
Be My API How to Implement an API Strategy Everyone will Love Be My API How to Implement an API Strategy Everyone will Love
Be My API How to Implement an API Strategy Everyone will Love
 
The future will be Serverless (FrontConf Munich 2017)
The future will be Serverless (FrontConf Munich 2017)The future will be Serverless (FrontConf Munich 2017)
The future will be Serverless (FrontConf Munich 2017)
 
Perspectives on Open
Perspectives on OpenPerspectives on Open
Perspectives on Open
 

Mais de CA API Management

5 steps end to end security consumer apps
5 steps end to end security consumer apps5 steps end to end security consumer apps
5 steps end to end security consumer apps
CA API Management
 

Mais de CA API Management (20)

Api architectures for the modern enterprise
Api architectures for the modern enterpriseApi architectures for the modern enterprise
Api architectures for the modern enterprise
 
Mastering Digital Channels with APIs
Mastering Digital Channels with APIsMastering Digital Channels with APIs
Mastering Digital Channels with APIs
 
Takeaways from API Security Breaches Webinar
Takeaways from API Security Breaches WebinarTakeaways from API Security Breaches Webinar
Takeaways from API Security Breaches Webinar
 
API Design Methodology - Mike Amundsen, Director of API Architecture, API Aca...
API Design Methodology - Mike Amundsen, Director of API Architecture, API Aca...API Design Methodology - Mike Amundsen, Director of API Architecture, API Aca...
API Design Methodology - Mike Amundsen, Director of API Architecture, API Aca...
 
Liberating the API Economy with Scale-Free Networks - Mike Amundsen, Director...
Liberating the API Economy with Scale-Free Networks - Mike Amundsen, Director...Liberating the API Economy with Scale-Free Networks - Mike Amundsen, Director...
Liberating the API Economy with Scale-Free Networks - Mike Amundsen, Director...
 
API360 – A How-To Guide for Enterprise APIs - Learn how to position your ente...
API360 – A How-To Guide for Enterprise APIs - Learn how to position your ente...API360 – A How-To Guide for Enterprise APIs - Learn how to position your ente...
API360 – A How-To Guide for Enterprise APIs - Learn how to position your ente...
 
API Monetization: Unlock the Value of Your Data
API Monetization: Unlock the Value of Your DataAPI Monetization: Unlock the Value of Your Data
API Monetization: Unlock the Value of Your Data
 
Revisiting Geddes' Outlook Tower - Mike Amundsen, Director of API Architectur...
Revisiting Geddes' Outlook Tower - Mike Amundsen, Director of API Architectur...Revisiting Geddes' Outlook Tower - Mike Amundsen, Director of API Architectur...
Revisiting Geddes' Outlook Tower - Mike Amundsen, Director of API Architectur...
 
Managing Identity by Giving Up Control - Scott Morrison, SVP & Distinguished ...
Managing Identity by Giving Up Control - Scott Morrison, SVP & Distinguished ...Managing Identity by Giving Up Control - Scott Morrison, SVP & Distinguished ...
Managing Identity by Giving Up Control - Scott Morrison, SVP & Distinguished ...
 
Enabling the Multi-Device Universe
Enabling the Multi-Device UniverseEnabling the Multi-Device Universe
Enabling the Multi-Device Universe
 
Building APIs That Last for Decades - Irakli Nadareishvili, Director of API S...
Building APIs That Last for Decades - Irakli Nadareishvili, Director of API S...Building APIs That Last for Decades - Irakli Nadareishvili, Director of API S...
Building APIs That Last for Decades - Irakli Nadareishvili, Director of API S...
 
The Art of API Design - Ronnie Mitra, Director of API Design, API Academy at ...
The Art of API Design - Ronnie Mitra, Director of API Design, API Academy at ...The Art of API Design - Ronnie Mitra, Director of API Design, API Academy at ...
The Art of API Design - Ronnie Mitra, Director of API Design, API Academy at ...
 
APIs Fueling the Connected Car Opportunity - Scott Morrison, SVP & Distinguis...
APIs Fueling the Connected Car Opportunity - Scott Morrison, SVP & Distinguis...APIs Fueling the Connected Car Opportunity - Scott Morrison, SVP & Distinguis...
APIs Fueling the Connected Car Opportunity - Scott Morrison, SVP & Distinguis...
 
Adapting to Digital Change: Use APIs to Delight Customers & Win
Adapting to Digital Change: Use APIs to Delight Customers & WinAdapting to Digital Change: Use APIs to Delight Customers & Win
Adapting to Digital Change: Use APIs to Delight Customers & Win
 
Balancing Security & Developer Enablement in Enterprise Mobility - Jaime Ryan...
Balancing Security & Developer Enablement in Enterprise Mobility - Jaime Ryan...Balancing Security & Developer Enablement in Enterprise Mobility - Jaime Ryan...
Balancing Security & Developer Enablement in Enterprise Mobility - Jaime Ryan...
 
5 steps end to end security consumer apps
5 steps end to end security consumer apps5 steps end to end security consumer apps
5 steps end to end security consumer apps
 
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
 
Drones, Phones & Pwns the Promise & Dangers of IoT APIs: Use APIs to Securely...
Drones, Phones & Pwns the Promise & Dangers of IoT APIs: Use APIs to Securely...Drones, Phones & Pwns the Promise & Dangers of IoT APIs: Use APIs to Securely...
Drones, Phones & Pwns the Promise & Dangers of IoT APIs: Use APIs to Securely...
 
Gartner AADI Summit Sydney 2014 Implementing the Layer 7 API Management Pla...
Gartner AADI Summit Sydney 2014   Implementing the Layer 7 API Management Pla...Gartner AADI Summit Sydney 2014   Implementing the Layer 7 API Management Pla...
Gartner AADI Summit Sydney 2014 Implementing the Layer 7 API Management Pla...
 
Using APIs to Create an Omni-Channel Retail Experience
Using APIs to Create an Omni-Channel Retail ExperienceUsing APIs to Create an Omni-Channel Retail Experience
Using APIs to Create an Omni-Channel Retail Experience
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Designing & Implementing Hypermedia APIs – Mike Amundsen, Principal API Architect, Layer 7

  • 1. 1 Designing and Implementing Hypermedia APIs QCon New York 2013  Mike Amundsen, Principal API Architect Layer 7 Techologies @mamund #HyperQCon
  • 2. 2 Mike Amundsen  Author, Web Architect, Presenter  Principal API Architect  Building Hypermedia APIs with HTML5 and Node  RESTful Web APIs (Richardson, Amundsen, Ruby)
  • 3. 3 Agenda  Hypermedia – the Short Story (15:00)  Designing Hypermedia APIs (10:00 )  Hack a Hypermedia API (30:00)  Implementing Hypermedia Servers (10 :00)  Hack a Hypermedia Server (45:00)  Building Hypermedia Clients (10:00)  Hack a Hypermedia Client (45:00)  Now What? (15:00)
  • 4. 4 Reminders  Bells & Whistles Off  Feel free to stretch, move about as needed  Ask Questions  Enjoy the Session
  • 6. 6 Atlas holds the weight of the world on his shoulders…
  • 7. 7 On the Shoulders of Giants
  • 8. 8 Vannevar Bush  Memex, 1945  Key project leader on the Manhattan Project to build the first nuclear bomb.  “ A memex …is an enlarged intimate supplement to … memory.”  “With one item in its grasp, [the mind] snaps instantly to the next that is suggested by the association of thoughts, in accordance with some intricate web of trails carried by the cells of the brain.”
  • 9. 9 Douglas Engelbart  Computer mouse, 1965  Key to creating the ARPANET while at Stanford Research, Institue (SRI).  “Augmenting Human Intellect”, 1962  “[A] new and systematic approach to improving the intellectual effectiveness of the individual human being … One of the tools that shows the greatest immediate promise is the computer.”
  • 10. 10 Ted Nelson  Hypertext, 1963  Identified and popularized early “cyber-culture” in 1979 book “Computer Lib/Machine Dreams”  “If computers are the wave of the future, displays are the surfboards.”
  • 11. 11 James J. Gibson  “The Ecological Approach to Visual Perception” (1986)  Coined the term “affordance”  Environments provide niches of appropriate affordances  Animals survive/thrive when they can exploit the affordances in their niche “An affordance is a quality of an object, or an environment, which allows an individual to perform an action.”
  • 12. 12 Donald Norman  The Design of Everyday Things, 1988  Action Lifecycle, Seven Stages of Action  “In the world” and “In the head”  “Simplification is as much in the mind as it is in the device.”  “Design is really an act of communication.”
  • 13. 13 Tim Berners-Lee  Tim Berners-Lee @ CERN 1980  ENQUIRE in 1984 (hypertext database)  Information Mgmt: A Proposal to CERN in 1989  HTTP (1992), HTML (1993), RDF (2004)  “A way to link and access information of various kinds as a web of nodes in which the user can browse at will.”
  • 14. 14 Roy T. Fielding  Architectural Styles and the Design of Network-based Software Architectures, 2000  Created “REST”  Key in the startup and operation of the “Apache Foundation”  Representations and Hypermedia  “A resource is not the thing that is transferred across the wire or picked up off the disk or seen from afar while walking your dog. Each of those is only a representation. Do I think of a different identifier every time I see my dog, or do I simply think of my dog as one identity and experience many representations of that identity over time (and on into memory and imagination)?
  • 15. 15 On the Shoulders of Giants
  • 20. 20 H-Factors  There are five LINK Factors (LO, LE, LT, LI, LN)  There are four CONTROL Factors (CR, CU, CM, CL)
  • 21. 21 H-Factors  There are five LINK Factors (LO, LE, LT, LI, LN)  There are four CONTROL Factors (CR, CU, CM, CL)
  • 24. 24 H-Factors Linking Outbound Links (LO) Embedded Links (LE) Templated Links (LT)
  • 25. 25 H-Factors Linking Outbound Links (LO) Embedded Links (LE) Templated Links (LT) Idempotent Links (LI)
  • 26. 26 H-Factors Linking Outbound Links (LO) Embedded Links (LE) Templated Links (LT) Idempotent Links (LI) Non-Idempotent Links (LN)
  • 27. 27 H-Factors  There are five LINK Factors (LO, LE, LT, LI, LN)  There are four CONTROL Factors (CR, CU, CM, CL)
  • 30. 30 H-Factors Control Request Controls (CR) Update Controls (CU) Method Controls (CM)
  • 31. 31 H-Factors Control Request Controls (CR) Update Controls (CU) Method Controls (CM) Link Controls (CL)
  • 32. 32 H-Factors  A collection of H-Factors is called a Hypermedia Type  By identifying H-Factors, you discover the “Hypermedia signature” of media type.
  • 33. 33 Three Pillars of Hypermedia Design
  • 34. 34
  • 35. 35 Three Pillars of Hypermedia Design  Structure Semantics (XML, JSON, YAML, etc.)  Protocol Semantics (HTTP, WS, FTP, etc.)  Application Domain Semantics (students, courseName, scheduleId, etc.)  All Web apps MUST support these somehow. What’s not in the message, is in the source code instead.
  • 36. 36 Three Pillars of Hypermedia Design Structure Semantics  How you communicate the layout of the response  Simple structures: - text/csv - application/xml - application/json  Advanced structures - text/html - application/atom+xml - application/vnd.hal+json - application/vnd.collection+json
  • 37. 37 Three Pillars of Hypermedia Design Protocol Semantics  How you communicate the possible actions in the response  Simple actions: - HTML.A - HTML.IMG - HTML.LINK  Advanced actions: - HTML.FORM@get - HTML.FORM@post - ATOM.LINK@edit - collection.queries.link@data[]
  • 38. 38 Three Pillars of Hypermedia Design Domain Semantics  How you communicate the domain-specific details in the response  Simple domain-specifics: - MAZE: collection, cell - VOICEXML: assign, transfer, disconnect, - ATOM: feed, entry, content  Advanced domain-specifics - HTML: @id, @name, @class, @rel - CJ: @id, @name, @value, @href - HAL: @rel, @name
  • 39. 39 Three Pillars of Hypermedia Design On the Web, media types don’t define a solution, they describe a problem domain
  • 40. 40 Three Pillars of Hypermedia Design The more descriptive the media type, the easier it is to talk about the problem.
  • 42. 42 Designing Hypermedia APIs Let’s describe the Class Scheduling domain…
  • 43. 43 Designing Hypermedia APIs Let’s describe the Class Scheduling domain… and let’s keep it real simple today.
  • 45. 45 Domain  Eleven data elements: - courseCapacity, courseDescription, courseId, courseName, scheduleId, scheduleSlot, studentId, studentName, studentStanding, teacherId, teacherName  Eight actions: - add, update, remove, read, list, filter, assign, unassign  Five identifiers: - home, course, student, teacher, schedule
  • 46. 46 Designing Hypermedia APIs Let’s map the actions to (at least) one Web protocol…
  • 47. 47 Designing Hypermedia APIs Let’s map the actions to (at least) one Web protocol… We could use HTTP, WebSockets, XMPP…
  • 48. 48 Designing Hypermedia APIs Let’s map the actions to (at least) one Web protocol… We could use HTTP, WebSockets, XMPP… But, of course, we’ll use HTTP today.
  • 49. 49 Protocol  Map eight actions: - add, update, remove, read, list, filter, assign, unassign  To four HTTP methods: - GET, POST, PUT, DELETE.
  • 50. 50 Designing Hypermedia APIs Let’s document the possible data elements for each action, too.
  • 51. 51 Data elements with actions…
  • 52. 52 Designing Hypermedia APIs Finally, let’s design a single message that can carry all that information…
  • 53. 53 Structure  Nine Elements - root, actions, link, list, item, template, display, data, error  Six Attributes - href, name, action, prompt, value, embed  Four Data Types - ID, URI, TEXT, BOOLEAN
  • 54. 54 Designing Hypermedia APIs Note we covered the three key aspects to each message design…
  • 55. 55 Designing Hypermedia APIs Note we covered the three key aspects to each message design… Structure
  • 56. 56 Designing Hypermedia APIs Note we covered the three key aspects to each message design… Structure Protocol
  • 57. 57 Designing Hypermedia APIs Note we covered the three key aspects to each message design… Structure Protocol Domain
  • 58. 58 Now let’s see some examples…
  • 59. 59
  • 60. 60 Let’s Design a Hypermedia API!
  • 62. 62 Implementing Hypermedia Servers  Components - Storage - Object Model/Processing  Connectors - Representation - Routing/Request Handling
  • 66. 66
  • 69. 69
  • 72. 72 Representation Layer  Representation happens in the Connector  HTTP supports content negotiation - Accept - Content-Type  Differing clients (user-agents) === differing representations - Desktop - Browser - Tablet - Smartphone  Be prepared to support multiple representations
  • 73. 73 Implementing Hypermedia Servers  Storage  Handles direct access to stored content (if any)  Database (MySQL, SQLServer, Oracle, CouchDB, Mongo, etc.)  File system (Local File I/O)  External Service (Salesforce, Amazon, Azure, etc.)  In-Memory (memcacheD, etc.)  Advice for this event: - Keep it simple - Use in-memory array for starter, add perm storage later - Use existing APIs (see listing today)
  • 74. 74 Implementing Hypermedia Servers  Components  Handles business rules and any processing/computing, etc.  Validate data/objects  Create any defaults or related data/objects  Enforce data integrity on writes  Enforce ACLs on reads/writes (skip for today)  Advice for this event: - Keep it simple - Consider read-only for today - Use existing APIs (see listing today)
  • 75. 75 Implementing Hypermedia Servers  Representation  Handles converting internal objects into external media type  *NOT* a serializer  Convert object graph into list/items  Include protocol affordances (links & forms)  Maps domain-specifics to appropriate elements/attributes/properties  Advice for this event: - Keep it simple - Consider using an existing hypermedia type - Use existing APIs (see listing today)
  • 76. 76 Implementing Hypermedia Servers  Routing  Handles incoming requests, routes to appropriate method/handler  Thin veneer behind API  NOT a direct wrapper for components  Converts request URL parts into arguments  Usually handles call to representation service for responses  MAY handle caching directives (skip for today)  Advice for this event: - Keep it simple - Consider a very simple URL routing pattern (/{thing}/{id}) - Use existing APIs (see listing today)
  • 77. 77 Let’s Build a Hypermedia Server!
  • 78. 78 Summary : Implementing Hypermedia Servers  Components - Storage (DB, FileSys, external) - Object Model/Processing (objects, business rules)  Connectors - Representation (convert object graph into media type) - Routing/Request Handling (convert URLs into args & route)
  • 80. 80 Building Hypermedia Clients  Hypermedia clients for humans  Hypermedia clients for machines
  • 82. 82 What is a Hypermedia for Humans client? A client that is able to determine possible protocol-level choices at runtime using only the links and forms in the message itself as a guide.
  • 83. 83 Some things to keep in mind… Hypermedia clients are based on the “Action Lifecycle”
  • 84. 84 Some things to keep in mind… http://en.wikipedia.org/wiki/Human_action_cycle
  • 85. 85 Some things to keep in mind… Oh!, I almost forgot…
  • 86. 86 Hypermedia clients Typically hypermedia clients have almost no long-term memory.
  • 87. 87 Hypermedia clients Typically hypermedia clients have almost no long-term memory. Hypermedia clients’ memories last for a single request/response cycle.
  • 88. 88 Hypermedia clients Typically hypermedia clients have almost no long-term memory. Hypermedia clients’ memories last for a single request/response cycle. Clients MAY save a past response, parse it, store it, and recall it later.
  • 89. 89 Faithful Hypermedia Clients (FHCs)  FHCs simply pass along whatever the server returns; usually to a human.  FHCs MAY make some decisions on how to display the returned representation  FHCs only need a starting URL and a (human) driver.
  • 90. 90 Guide for implementing an FHC  Process the structure semantics in order to render view  Process the protocol semantics in order to support available transitions  Process the domain semantics in order to inform human of choices & results.
  • 99. 99 Summary for the Class Schedule FHC  Structure Semantics - Take advantage of client-side XSLT - Build XSL processor for vnd.apiacademy-scheduling+xml - 120 lines of XSLT  Protocol Semantics - Take advantage of XmlHttpRequest - Provide a single JS file that “understands” vnd.apiacademy-scheduling+xml - 130 lines of JS  Domain Semantics - Use CSS to hide/show things for humans (.id, .dateCreated) - 130 lines of CSS
  • 100. 100 Advantages of hypermedia clients for humans  Flexibility to support a wide range of non-breaking domain-level changes - Adding new display & input fields - Adding new resources/pages - Adding new link and form options (not new protocol options) - Changes in access control rules is “automatic” (No access? No controls!)  Ability to separate “parsing” from “display” - Most hypermedia types keep clear separation between processing and display - Can make it easier to handle negotiations between server devs and UI devs  Ability to customize engines for devices - Same hypermedia message can be handled differently on each device, when applicable - Increased freedom for UI devs
  • 101. 101 Drawbacks of hypermedia clients for humans  SoC can mean extra work for clients - Need to keep structure, protocol, domain clearly separated  Possibility of changes in server can limit UI options - UI devs must plan for change (even before it happens)  Anything short of FHC risks client adaptability - If client determines what to display, new fields will not appear. - If client determines what transitions to support and in what order they appear, changes (add/ move forms & links) may break the client.  If the message format is unstable (breaking changes occurring), FHCs have no real advantage over one-off client coding.
  • 103. 103 What is a hypermedia machine client? A client that is able to process responses, locate protocol actions, and make domain-level choices at runtime using only the links and forms in the message itself as a guide.
  • 104. 104 What is a hypermedia machine client? A client that is able to process responses, locate protocol actions, and make domain-level choices at runtime using only the links and forms in the message itself as a guide.
  • 105. 105 Agent Hypermedia Clients (AHCs)  AHCs can process all three levels of messages: - Structure - Protocol - Domain  AHCs MUST be able to make decisions on their own  AHCs need only a starting URL  http://xkcd.com/695/
  • 106. 106 Guide for implementing an AHC  Process the structure semantics in order to know what’s “there”  Process the protocol semantics in order to know what’s possible  Process the domain semantics in order to make an informed choice  The machine is in charge of the complete “Action Lifecycle”
  • 114. 114 Summary for Maze+XML AHC  Structure Semantics - XML DOM Parser + recognizing five elements (maze, collection, item,cell, link)  Protocol Semantics - Support maze:link (H-factor=LO, HTTP.GET)  Domain Semantics - Understand “wall-following” and choose between “start”, “north”, “south”, “east”, west”, and “exit”  150 lines of NodeJS code
  • 115. 115 Advantages of hypermedia clients for machines  Ability to hand off tedious work to “smart” machine  Using “generic” media types makes it possible to use the same client code for several different tasks/projects  Coding new tasks gets faster over time since the baseline code already exists  Simple modifications in the server (order to items in message) don’t break clients
  • 116. 116 Drawbacks of hypermedia clients for machines  Making machines “smart” takes time, esp. for non-trivial tasks  Some changes in message can break clients (missing transitions, new fields, etc.)  Some unsafe operations (POST/PUT/DELETE) may need human intervention anyway.  Not many “machine-friendly” hypermedia types yet.
  • 117. 117 Let’s Build a Hypermedia Client!
  • 118. 118 Summary : Building Hypermedia Clients  Hypermedia clients for humans (FHC) - A client that is able to determine possible protocol-level choices at runtime using only the links and forms in the message itself as a guide.  Hypermedia clients for machines (AHC) - A client that is able to process responses, locate protocol actions, and make domain-level choices at runtime using only the links and forms in the message itself as a guide.  Hypermedia clients are based on the “Action Lifecycle”  Hypermedia clients’ memories usually last for a single request/response cycle.
  • 120. 120 Now What?  Hypermedia goes back more than ½ a century  Remember the H-Factors (LO, LE, LT, LI, LN, CR, CU, CM, CL)  Always solve for the Three Pillars (Structure, Protocol, Domain)  Servers have: - Components (Storage & Processing) - Connectors (Routing & Representation)  Clients have: - No long-term memory - Support for Action Lifecycle - FHCs (for humans) - ACHs (for machines)
  • 121. 121 Let’s Grow the Hypermedia Web!
  • 122. 122 Available Server Projects  YouTypeItWePostIt (:8080/api/) - https://github.com/mamund/rwa  Maze+XML (:8181) - https://github.com/mamund/rwa  Class-Schedule (:8282) - https://github.com/apiacademy/class-scheduling  To-Do-REST (:8383) - https://github.com/mamund/to-do-rest
  • 123. 123 Designing and Implementing Hypermedia APIs QCon New York 2013  Mike Amundsen, Principal API Architect Layer 7 Techologies @mamund #HyperQCon