SlideShare a Scribd company logo
Hypermedia Design
for
Machine APIs
Web Scale Architecture for the Web of Things
Michael J Koster
14 September 2015
Fielding 4.3 [Fielding2000]
β€’ Hypothesis I: The design rationale behind the WWW
architecture can be described by an architectural style
consisting of the set of constraints applied to the elements
within the Web architecture.
β€’ Hypothesis II: Constraints can be added to the WWW
architectural style to derive a new hybrid style that better
reflects the desired properties of a modern Web
architecture.
β€’ Hypothesis III: Proposals to modify the Web architecture
can be compared to the updated WWW architectural style
and analyzed for conflicts prior to deployment.
What is REST?
β€’ Exchange of state information
between applications and
resources
β€’ Resource State is part of the
application state
β€’ State is exchanged through
representations of the resource
β€’ Application state is updated by
application obtaining a current
representation of the resource
β€’ Resource state is updated by
application transmitting a new
representation of the resource
Application
Resource
Representations of
State Information
What is HATEOAS?
β€’ Hypermedia As The Engine Of Application
State
β€’ Hypermedia is the descriptive metadata about
how to exchange state information between
applications and resources
β€’ An application can read the hypermedia and
automatically consume resources
β€’ Such an interface is machine-understandable
β€’ Hypermedia defines REST [Fielding 2008]
Hypermedia Controls for HTML
β€’ Links and Forms embedded in the resource
representations of web pages constitute a
hypermedia interaction model for HTML
β€’ Links describe how and where to obtain a
resource state representation and how to use
it to update application state
β€’ Forms describe how and where to transmit a
representation of the resource to update the
resource state
How Links Work
β€’ Applications update their state by consuming
resources indicated by links and incorporating
the resource state into the application state
β€’ The semantics of a link are β€œ{Current Context}
has a {Relation Type} Resource at {Target URI}
which has {Target Attributes}” [Hartke2015]
β€’ Relation Type indicates how the Target
Resource is related to the Current Context
β€’ Target Attributes may include media type
Embedding Links
β€’ There are outbound links, described above,
and embedding links
β€’ Embedding links enable the embedding of
resources within the Current Context
β€’ Examples are <img> and <script> tags in HTML
β€’ Linked embedded resources are processed as
part of the Current Context
How Forms Work
β€’ Applications update the state of resources by
submitting representations according to the meta
data instructions provided by the form
β€’ The semantics of a form are β€œTo {Relation Type}
{Current Context}, perform a {Request
Description} to {Target URI} [Hartke2015]
β€’ Relation Type indicates the desired action on the
Current Context, e.g. Add an article to a blog
β€’ A form can also be used with GET to create a
typed outbound link according to a URL template
The Collection Pattern
β€’ Very common design pattern [WEBAPIS]
β€’ Good example of the use of HATEOAS
β€’ Collection is a resource that contains links to resources,
which are items in the collection
β€’ Application uses links to list items and obtain links to
resources in the collection
β€’ Application uses forms to add items to, or remove
items from the collection
β€’ Adding an item to the collection adds a link to a
resource to the collection
β€’ Removing an item from the collection removes the link
to the resource from the collection
Hypermedia Languages
β€’ HTML – Links and Forms embedded in web pages
β€’ Microdata – Schema.org; RDFa metadata
embedded in web pages
β€’ CoRE Link Format (RFC 6690)
β€’ JSON-LD – WoT Thing Description Language
β€’ (Many others)
β€’ How is the hypermedia control exposed in the
API?
β€’ How does it drive application state?
Thing Description Language
β€’ What are Events, Actions, and Properties?
– Elements of the WoT Interaction Model
– Resource Classes with hypermedia controls
β€’ Re-use the semantics of HTML Links and
Forms but for machine interactions
β€’ HATEOAS for machine APIs
The Action Pattern
β€’ Used to invoke Actions on a target resource
β€’ Parameters are controls on the execution of the action
β€’ The Action is invoked with a binding to a particular set of
parameters
β€’ Parameters may be mapped to defined resources or
properties
β€’ Invoking an action creates a reference to a representation
of a new instance of the action scheduled to be executed
on the target resource
β€’ Action instances are reference-able entities that may be
used to modify or cancel the execution of an action which
is currently executing or pending execution
β€’ Actions may be removed from the system after the
completion of execution of the action has been handled
β€’ Actions may use the collection pattern
The Event Pattern - Subscriptions
β€’ Events are emitted from a target resource to
transmit state information asynchronously
β€’ An event may contain a representation of
resource state
β€’ A resource has associated with it a collection of
event types it can emit
β€’ The Subscription pattern is used to associate a
particular event type and condition set with the
invocation of a protocol handler
β€’ Each event type may have an associated
collection of Subscription resources
The Event Pattern – Notifications
β€’ Each event occurrence creates a new resource,
which is added to a collection of event
occurrences for each Subscription
β€’ Each event occurrence may have associated with
it a notification
β€’ A notification is a protocol handler which sends
an event message to a target resource or handler
location defined by a URL
β€’ Sending of event messages may be abstracted by
hypermedia controls embedded in the
Subscription resource
HATEOAS Design for the WoT Interaction Model
Resource
Class
Hypermedia Controls
Actions - Form-like constructs use POST to execute actions based on
parameters mapped to resources
- POST creates a new Action resource and schedules the
action for execution
- Action resources are used to track and control ongoing
execution of actions
Events - Form-like constructs use POST to create and subscribe to
Events
- Events use the Subscription Resource pattern
- Events and Subscriptions are managed in collections
Properties - Links and attributes provide a simple hypermedia control
for getting and setting property values using GET and PUT
- Properties may be of any media type
Hypermedia Controls for Machine APIs
β€’ Some common attributes and semantic
features could be useful for machine APIs
β€’ Describe media types in Actions and Events
β€’ Add parameters to Actions and Events
β€’ Describe Data Types and Data Templates
β€’ Provide for additional methods, PUT, PATCH
β€’ Provide a way to process response codes and
response metadata from the resource
Lighting Domain Example
β€’ Professional lighting controls based on a popular
control model
β€’ Actions for on-off control, dimming, and color
control for various colorspaces are encapsulated
in optional capability modules
β€’ Various control modes are optionally supported:
Change, Step, Move, Toggle
β€’ Control abstractions allow for controllable timed
and smooth transitions between resource states
Control Model for Lighting
light
onOff
level
color
change
toggle
newState:
{enum:off,on}
HS
XY
temperature
change
step
move
targetValue:{units:%}
transitionTime
rate:{units:%/s}
stepSize
stop
transitionTime:{units:s}
change
step
move
targetValue:{units:K,
range:2700-5500}
transitionTime
rate:{units:K/s}
stepSize
transitionTime:{units:s}
stop
light.onOff.change
{newState:on}
light.color.temperature.change
{targetValue:3400,
transitionTime:10}
light.level.change
{targetValue:45,
transitionTime:10}
thing actuators actions parameters application actions {parameters}
(colorspace)
Example Hypertext Links to Properties
hypertext links at resource context = /light
[{
β€œrel”: β€œproperty”,
β€œhref”: β€œColorTemp/currentValue”,
β€œtype”: β€œobservable”,
β€œname”: β€œColorTemperature”
},{
β€œrel”: β€œproperty”,
β€œhref”: β€œColorTemp/remTime”,
β€œtype”: β€œobservable”,
β€œname”: β€œTransitionTimeRemaining”
}]
/light has observable property resources:
β€œColorTemperature” at the URI /light/ColorTemp/currentValue
β€œTransitionTimeRemaining” at the URI /light/ColorTemp/remTime
Hypertext Link to Actuator
hypertext link at resource context = /light
{
β€œrel”: β€œaction”,
β€œhref”: β€œColorTemp”,
β€œtype”: β€œactuator”,
β€œname”: β€œColorTemperature”
}
β€œ/light has an actuator type action resource named ColorTemperature at
the URI /light/ColorTemp”
Hypertext Form for Change Action
hypertext form at resource context = /light/ColorTemp:
{
β€œrel”: β€œaction”, β€œtype”: β€œaction”, β€œname”: β€œChange”,
β€œmethod”: β€œPOST”, β€œhref”: β€œActions”
β€œcontent-format”: β€œapplication/tdlactions+json”,
β€œparameters”:[ {β€œname”: β€œtargetValue”, β€œdataType”: β€œfloat”},
{β€œname”: β€œtransitionTime”,
β€œdataType”:”float”, β€œunits”: β€œs”}]
β€œtemplate”: β€œ{ β€œchangeTemp”: β€œ$targetValue”,
β€œtransTime”: β€œ$transitionTime” }”,
β€œreturns”: [{β€œresponseCode”: β€œ201”,
β€œresponseAction”: β€œsuccess”
β€œparameters”: [{β€œtype”: β€œheader”,
β€œname”: β€œLocation”,
β€œtype”: β€œhref”
β€œrel”: β€œactionInstance” }],
]}
To Change the ColorTemperature of /light, POST a template containing targetValue and
transition Time parameters to the resource at /light/ColorTemp/Actions. Expect a
responseCode of 201 if success and expect to find an actionInstance resource pointed to by the
header parameter named β€œLocation”.
Hypertext Form for Step Action
hypertext form at resource context = /light/ColorTemp:
{
β€œrel”: β€œaction”, β€œtype”: β€œaction”, β€œname”: β€œStep”,
β€œmethod”: β€œPOST”, β€œhref”: β€œActions”
β€œcontent-format”: β€œapplication/tdlactions+json”,
β€œparameters”:[ {β€œname”: β€œstepSize”, β€œdataType”: β€œfloat”},
{β€œname”: β€œtransitionTime”,
β€œdataType”:”float”, β€œunits”: β€œs”}]
β€œtemplate”: β€œ{ β€œstepSize”: β€œ$stepSize”,
β€œtransTime”: β€œ$transitionTime” }”,
β€œreturns”: [{β€œresponseCode”: β€œ201”,
β€œresponseAction”: β€œsuccess”
β€œparameters”: [{β€œtype”: β€œheader”,
β€œname”: β€œLocation”,
β€œtype”: β€œhref”
β€œrel”: β€œactionInstance” }],
]}
To Step the ColorTemperature of /light, POST a template containing stepSize and transition
Time parameters to the resource at /light/ColorTemp/Actions. Expect a responseCode of 201 if
success and expect to find an actionInstance resource pointed to by the header parameter
named β€œLocation”.
Hypertext Form for Move Action
hypertext form at resource context = /light/ColorTemp:
{
β€œrel”: β€œaction”, β€œtype”: β€œaction”, β€œname”: β€œMove”,
β€œmethod”: β€œPOST”, β€œhref”: β€œActions”
β€œcontent-format”: β€œapplication/tdlactions+json”,
β€œparameters”:[ {β€œname”: β€œmoveRate”, β€œdataType”: β€œfloat”,
β€œunits”: β€œK/s”}]
β€œtemplate”: β€œ{β€œrate”: β€œ$moveRate”}”,
β€œreturns”: [{β€œresponseCode”: β€œ201”,
β€œresponseAction”: β€œsuccess”
β€œparameters”: [{β€œtype”: β€œheader”,
β€œname”: β€œLocation”,
β€œtype”: β€œhref”
β€œrel”: β€œactionInstance” }],
]}
To Move the ColorTemperature of /light, POST a template containing the moveRate parameter
to the resource at /light/ColorTemp/Actions. Expect a responseCode of 201 if success and
expect to find an actionInstance resource pointed to by the header parameter named
β€œLocation”.
β€’ Can be discovered by the application as the result of a gradual reveal
process guided by an ontology, e.g. ColorTemperature control with
ChangeValue control semantics
β€’ The name can be rendered to the application based on discovered names
populated from well known namespaces e.g. Schema.org
β€’ Actions can be invoked by reusable handlers for well known data and
control models
β€’ Example serialization of an action and invocation using discovered names
with values supplied from a scene controller: action=
my_light.ColorTemperature.Change(targetValue=2900,
TransitionTime=10)
β€’ The hypermedia control generates this transaction: POST
uri=/light/ColorTemp/Actions pl={β€œchangeTemp”: β€œ2900”,
β€œtransTime”: β€œ10”}
β€’ A success response contains the URI of the Action resource in the location
header: 201 Created Location: ac3f5774
β€’ Execution of the action can be controlled through the Action resource:
action.cancel() DELETE uri=/light/ColorTemp/Actions/ac3f5774
Application Interface Mapping
Hypertext Link – CoAP + IPSO Binding
hypertext link at resource context = /light
{
β€œrel”: β€œaction”,
β€œhref”: β€œ3004/0”,
β€œtype”: β€œactuator”,
β€œname”: β€œColorTemperature”
}
β€œ/light has an action resource at the URI /light/3004/0 of type actuator
named ColorTemperature”
Hypertext Form – CoAP + IPSO Binding
hypertext form for CoAP binding, resource context = /light/3004/0:
{
β€œrel”: β€œaction”, β€œtype”: β€œaction”, β€œname”: β€œChange”,
β€œmethod”: β€œPOST”, β€œhref”: β€œ5052”
β€œcontent-format”: β€œapplication/ipso+senml+json”,
β€œparameters”:[ {β€œname”: β€œtargetValue”, β€œdataType”: β€œfloat”},
{β€œname”: β€œtransitionTime”,
β€œdataType”:”float”, β€œunits”: β€œs”}]
β€œtemplate”: β€œ[{β€œn”: β€œ5059”, β€œv”: β€œ$targetValue”}
{β€œn”: β€œ5002”, β€œv”: β€œ$transitionTime”}]”,
β€œreturns”: [{β€œresponseCode”: β€œ2.01”,
β€œresponseAction”: β€œsuccess”
β€œparameters”: [{β€œtype”: β€œheader”,
β€œname”: β€œLocation”,
β€œtype”: β€œhref”
β€œrel”: β€œactionInstance” }],
]}
To Change the ColorTemperature of /light, POST a template containing targetValue and
transition Time parameters to the resource at /light/3004/0/5052. Expect a responseCode of
2.01 if success and expect to find an actionInstance resource pointed to by the header
parameter named β€œLocation”
β€’ Example serialization of an action and invocation using
discovered names with values supplied from a scene
controller: action=
my_light.ColorTemperature.Change(targetValue=2900,
TransitionTime=10)
β€’ The IPSO + CoAP hypermedia control generates this request:
POST uri=/light/3004/0/5052
pl=[{β€œn”:β€œ5059”,β€œv”:β€œ2900”},{β€œn”:β€œ5002”,β€œv”:β€œ10”}]
β€’ A success response contains the URI of the Action resource in
the location header: 2.01 Created Location: 17
β€’ Execution of the action can be controlled through the Action
resource: action.cancel() DELETE
uri=/light/3004/0/5052/17
Uniform Application Interface,
Hypermedia Controls for IPSO + CoAP
References
β€’ [Fielding2000]
http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
β€’ [Fielding2008] http://roy.gbiv.com/untangled/2008/rest-apis-
must-be-hypertext-driven
β€’ [WEBAPIS] Richardson, L. and M. Amundsen, "RESTful Web
APIs”, O'Reilly, September 2013.
β€’ [Hartke2015] https://tools.ietf.org/html/draft-hartke-core-
apps-01 https://tools.ietf.org/html/draft-hartke-core-lighting-
00

More Related Content

PPTX
Hypermedia for Machine APIs
PPTX
Embedded to connected
PPTX
Hypermedia System Architecture for a Web of Things
PDF
Ipso eclipse-summary
PPTX
Web of Things to the edge
PPTX
Iottoolkit wot
PDF
IoT Toolkit and the Smart Object API Tutorial Introduction
PDF
A Modular Open Source Platform for IoT
Hypermedia for Machine APIs
Embedded to connected
Hypermedia System Architecture for a Web of Things
Ipso eclipse-summary
Web of Things to the edge
Iottoolkit wot
IoT Toolkit and the Smart Object API Tutorial Introduction
A Modular Open Source Platform for IoT

What's hot (16)

PDF
Iottoolkit osiot
PDF
REST APIs for the Internet of Things
PDF
Object models for interoperability
PPTX
Ipso smart object seminar
PDF
Iot Toolkit and the Smart Object API - Architecture for Interoperability
PPTX
Hypermedia System Architecture for a Web of Things
PDF
CCNA-Open-Platform-IoT
PPTX
IP based standards for IoT
PPTX
Research Topics in Machine Hypermedia
PDF
A Modular Open Source Platform for Web Scale IoT Interoperability
PPTX
Restful Asynchronous Notification
PPTX
Ipso application templates
PPTX
OMA LwM2M Workshop - Michael Koster, IPSO Alliance Objects
PDF
Streaming Visualization
PDF
Building event-driven Microservices with Kafka Ecosystem
PDF
Kafka as an event store - is it good enough?
Iottoolkit osiot
REST APIs for the Internet of Things
Object models for interoperability
Ipso smart object seminar
Iot Toolkit and the Smart Object API - Architecture for Interoperability
Hypermedia System Architecture for a Web of Things
CCNA-Open-Platform-IoT
IP based standards for IoT
Research Topics in Machine Hypermedia
A Modular Open Source Platform for Web Scale IoT Interoperability
Restful Asynchronous Notification
Ipso application templates
OMA LwM2M Workshop - Michael Koster, IPSO Alliance Objects
Streaming Visualization
Building event-driven Microservices with Kafka Ecosystem
Kafka as an event store - is it good enough?
Ad

Similar to Hypermedia design for machine apis (20)

PPTX
API & Backend Integration
PDF
Design patternsforiot
PPTX
Spring Web Presentation 123143242341234234
PDF
Moulding your enterprise with ROA
Β 
PDF
Apply API Governance to RESTful Service APIs using WSO2 Governance Registry a...
Β 
PDF
Semantic Technologies for Enterprise Cloud Management
PPTX
ASP.NET Mvc 4 web api
PDF
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid Rahimian
PPT
COLLECTION METHODS
PDF
M2M Protocol Interoperability using IoT Toolkit
PDF
M2M Protocol Interoperability using IoT Toolkit
PPTX
Asp introduction
PPTX
SPSNYC14 - Must Love Term Sets: The New and Improved Managed Metadata Service...
PDF
REST APIs for an Internet of Things
PPTX
About HTTP and REST
PPTX
#ImpactSalesforceSaturday:360 degree view of salesforce integrations
PPTX
Model View Controller-Introduction-Overview.pptx
PPTX
Approaches to machine actionable links
PPT
Semantic Web Servers
PDF
IoT Toolkit and the Smart Object API - Architecture for Interoperability
API & Backend Integration
Design patternsforiot
Spring Web Presentation 123143242341234234
Moulding your enterprise with ROA
Β 
Apply API Governance to RESTful Service APIs using WSO2 Governance Registry a...
Β 
Semantic Technologies for Enterprise Cloud Management
ASP.NET Mvc 4 web api
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid Rahimian
COLLECTION METHODS
M2M Protocol Interoperability using IoT Toolkit
M2M Protocol Interoperability using IoT Toolkit
Asp introduction
SPSNYC14 - Must Love Term Sets: The New and Improved Managed Metadata Service...
REST APIs for an Internet of Things
About HTTP and REST
#ImpactSalesforceSaturday:360 degree view of salesforce integrations
Model View Controller-Introduction-Overview.pptx
Approaches to machine actionable links
Semantic Web Servers
IoT Toolkit and the Smart Object API - Architecture for Interoperability
Ad

More from Michael Koster (12)

PPTX
Osiot14 buildout
PDF
Osiot13 IoT buildout
PPTX
Ipso smart objects for iot
PPTX
Ietf91 ad hoc-coap-lwm2m-ipso
PDF
MQTT REST Bridge using the Smart Object API
PPTX
The Network Effect - Open Source and the Internet Of Things - Helsinki Keynote
PDF
Tools for the Open Source Internet of Things
PPTX
Open Standards for IoT - GSM Workshop on IoT Standards Atlanta 2013
PDF
Personal Agency on the IoT
PDF
Open Horizontal Platform - Web Scale Interoperability for the Internet of Thi...
PDF
Friend Of A Thing and IoT Resource access control #OSIOT
PDF
MQTT - REST Bridge using the Smart Object API
Osiot14 buildout
Osiot13 IoT buildout
Ipso smart objects for iot
Ietf91 ad hoc-coap-lwm2m-ipso
MQTT REST Bridge using the Smart Object API
The Network Effect - Open Source and the Internet Of Things - Helsinki Keynote
Tools for the Open Source Internet of Things
Open Standards for IoT - GSM Workshop on IoT Standards Atlanta 2013
Personal Agency on the IoT
Open Horizontal Platform - Web Scale Interoperability for the Internet of Thi...
Friend Of A Thing and IoT Resource access control #OSIOT
MQTT - REST Bridge using the Smart Object API

Recently uploaded (20)

PPTX
Digital Literacy And Online Safety on internet
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
Β 
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Β 
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PDF
Introduction to the IoT system, how the IoT system works
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PPTX
E -tech empowerment technologies PowerPoint
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PPTX
international classification of diseases ICD-10 review PPT.pptx
Digital Literacy And Online Safety on internet
Introuction about ICD -10 and ICD-11 PPT.pptx
Slides PPTX World Game (s) Eco Economic Epochs.pptx
RPKI Status Update, presented by Makito Lay at IDNOG 10
Β 
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
The New Creative Director: How AI Tools for Social Media Content Creation Are...
Unit-1 introduction to cyber security discuss about how to secure a system
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Β 
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
Introduction to the IoT system, how the IoT system works
SASE Traffic Flow - ZTNA Connector-1.pdf
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
E -tech empowerment technologies PowerPoint
WebRTC in SignalWire - troubleshooting media negotiation
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Introuction about WHO-FIC in ICD-10.pptx
Cloud-Scale Log Monitoring _ Datadog.pdf
international classification of diseases ICD-10 review PPT.pptx

Hypermedia design for machine apis

  • 1. Hypermedia Design for Machine APIs Web Scale Architecture for the Web of Things Michael J Koster 14 September 2015
  • 2. Fielding 4.3 [Fielding2000] β€’ Hypothesis I: The design rationale behind the WWW architecture can be described by an architectural style consisting of the set of constraints applied to the elements within the Web architecture. β€’ Hypothesis II: Constraints can be added to the WWW architectural style to derive a new hybrid style that better reflects the desired properties of a modern Web architecture. β€’ Hypothesis III: Proposals to modify the Web architecture can be compared to the updated WWW architectural style and analyzed for conflicts prior to deployment.
  • 3. What is REST? β€’ Exchange of state information between applications and resources β€’ Resource State is part of the application state β€’ State is exchanged through representations of the resource β€’ Application state is updated by application obtaining a current representation of the resource β€’ Resource state is updated by application transmitting a new representation of the resource Application Resource Representations of State Information
  • 4. What is HATEOAS? β€’ Hypermedia As The Engine Of Application State β€’ Hypermedia is the descriptive metadata about how to exchange state information between applications and resources β€’ An application can read the hypermedia and automatically consume resources β€’ Such an interface is machine-understandable β€’ Hypermedia defines REST [Fielding 2008]
  • 5. Hypermedia Controls for HTML β€’ Links and Forms embedded in the resource representations of web pages constitute a hypermedia interaction model for HTML β€’ Links describe how and where to obtain a resource state representation and how to use it to update application state β€’ Forms describe how and where to transmit a representation of the resource to update the resource state
  • 6. How Links Work β€’ Applications update their state by consuming resources indicated by links and incorporating the resource state into the application state β€’ The semantics of a link are β€œ{Current Context} has a {Relation Type} Resource at {Target URI} which has {Target Attributes}” [Hartke2015] β€’ Relation Type indicates how the Target Resource is related to the Current Context β€’ Target Attributes may include media type
  • 7. Embedding Links β€’ There are outbound links, described above, and embedding links β€’ Embedding links enable the embedding of resources within the Current Context β€’ Examples are <img> and <script> tags in HTML β€’ Linked embedded resources are processed as part of the Current Context
  • 8. How Forms Work β€’ Applications update the state of resources by submitting representations according to the meta data instructions provided by the form β€’ The semantics of a form are β€œTo {Relation Type} {Current Context}, perform a {Request Description} to {Target URI} [Hartke2015] β€’ Relation Type indicates the desired action on the Current Context, e.g. Add an article to a blog β€’ A form can also be used with GET to create a typed outbound link according to a URL template
  • 9. The Collection Pattern β€’ Very common design pattern [WEBAPIS] β€’ Good example of the use of HATEOAS β€’ Collection is a resource that contains links to resources, which are items in the collection β€’ Application uses links to list items and obtain links to resources in the collection β€’ Application uses forms to add items to, or remove items from the collection β€’ Adding an item to the collection adds a link to a resource to the collection β€’ Removing an item from the collection removes the link to the resource from the collection
  • 10. Hypermedia Languages β€’ HTML – Links and Forms embedded in web pages β€’ Microdata – Schema.org; RDFa metadata embedded in web pages β€’ CoRE Link Format (RFC 6690) β€’ JSON-LD – WoT Thing Description Language β€’ (Many others) β€’ How is the hypermedia control exposed in the API? β€’ How does it drive application state?
  • 11. Thing Description Language β€’ What are Events, Actions, and Properties? – Elements of the WoT Interaction Model – Resource Classes with hypermedia controls β€’ Re-use the semantics of HTML Links and Forms but for machine interactions β€’ HATEOAS for machine APIs
  • 12. The Action Pattern β€’ Used to invoke Actions on a target resource β€’ Parameters are controls on the execution of the action β€’ The Action is invoked with a binding to a particular set of parameters β€’ Parameters may be mapped to defined resources or properties β€’ Invoking an action creates a reference to a representation of a new instance of the action scheduled to be executed on the target resource β€’ Action instances are reference-able entities that may be used to modify or cancel the execution of an action which is currently executing or pending execution β€’ Actions may be removed from the system after the completion of execution of the action has been handled β€’ Actions may use the collection pattern
  • 13. The Event Pattern - Subscriptions β€’ Events are emitted from a target resource to transmit state information asynchronously β€’ An event may contain a representation of resource state β€’ A resource has associated with it a collection of event types it can emit β€’ The Subscription pattern is used to associate a particular event type and condition set with the invocation of a protocol handler β€’ Each event type may have an associated collection of Subscription resources
  • 14. The Event Pattern – Notifications β€’ Each event occurrence creates a new resource, which is added to a collection of event occurrences for each Subscription β€’ Each event occurrence may have associated with it a notification β€’ A notification is a protocol handler which sends an event message to a target resource or handler location defined by a URL β€’ Sending of event messages may be abstracted by hypermedia controls embedded in the Subscription resource
  • 15. HATEOAS Design for the WoT Interaction Model Resource Class Hypermedia Controls Actions - Form-like constructs use POST to execute actions based on parameters mapped to resources - POST creates a new Action resource and schedules the action for execution - Action resources are used to track and control ongoing execution of actions Events - Form-like constructs use POST to create and subscribe to Events - Events use the Subscription Resource pattern - Events and Subscriptions are managed in collections Properties - Links and attributes provide a simple hypermedia control for getting and setting property values using GET and PUT - Properties may be of any media type
  • 16. Hypermedia Controls for Machine APIs β€’ Some common attributes and semantic features could be useful for machine APIs β€’ Describe media types in Actions and Events β€’ Add parameters to Actions and Events β€’ Describe Data Types and Data Templates β€’ Provide for additional methods, PUT, PATCH β€’ Provide a way to process response codes and response metadata from the resource
  • 17. Lighting Domain Example β€’ Professional lighting controls based on a popular control model β€’ Actions for on-off control, dimming, and color control for various colorspaces are encapsulated in optional capability modules β€’ Various control modes are optionally supported: Change, Step, Move, Toggle β€’ Control abstractions allow for controllable timed and smooth transitions between resource states
  • 18. Control Model for Lighting light onOff level color change toggle newState: {enum:off,on} HS XY temperature change step move targetValue:{units:%} transitionTime rate:{units:%/s} stepSize stop transitionTime:{units:s} change step move targetValue:{units:K, range:2700-5500} transitionTime rate:{units:K/s} stepSize transitionTime:{units:s} stop light.onOff.change {newState:on} light.color.temperature.change {targetValue:3400, transitionTime:10} light.level.change {targetValue:45, transitionTime:10} thing actuators actions parameters application actions {parameters} (colorspace)
  • 19. Example Hypertext Links to Properties hypertext links at resource context = /light [{ β€œrel”: β€œproperty”, β€œhref”: β€œColorTemp/currentValue”, β€œtype”: β€œobservable”, β€œname”: β€œColorTemperature” },{ β€œrel”: β€œproperty”, β€œhref”: β€œColorTemp/remTime”, β€œtype”: β€œobservable”, β€œname”: β€œTransitionTimeRemaining” }] /light has observable property resources: β€œColorTemperature” at the URI /light/ColorTemp/currentValue β€œTransitionTimeRemaining” at the URI /light/ColorTemp/remTime
  • 20. Hypertext Link to Actuator hypertext link at resource context = /light { β€œrel”: β€œaction”, β€œhref”: β€œColorTemp”, β€œtype”: β€œactuator”, β€œname”: β€œColorTemperature” } β€œ/light has an actuator type action resource named ColorTemperature at the URI /light/ColorTemp”
  • 21. Hypertext Form for Change Action hypertext form at resource context = /light/ColorTemp: { β€œrel”: β€œaction”, β€œtype”: β€œaction”, β€œname”: β€œChange”, β€œmethod”: β€œPOST”, β€œhref”: β€œActions” β€œcontent-format”: β€œapplication/tdlactions+json”, β€œparameters”:[ {β€œname”: β€œtargetValue”, β€œdataType”: β€œfloat”}, {β€œname”: β€œtransitionTime”, β€œdataType”:”float”, β€œunits”: β€œs”}] β€œtemplate”: β€œ{ β€œchangeTemp”: β€œ$targetValue”, β€œtransTime”: β€œ$transitionTime” }”, β€œreturns”: [{β€œresponseCode”: β€œ201”, β€œresponseAction”: β€œsuccess” β€œparameters”: [{β€œtype”: β€œheader”, β€œname”: β€œLocation”, β€œtype”: β€œhref” β€œrel”: β€œactionInstance” }], ]} To Change the ColorTemperature of /light, POST a template containing targetValue and transition Time parameters to the resource at /light/ColorTemp/Actions. Expect a responseCode of 201 if success and expect to find an actionInstance resource pointed to by the header parameter named β€œLocation”.
  • 22. Hypertext Form for Step Action hypertext form at resource context = /light/ColorTemp: { β€œrel”: β€œaction”, β€œtype”: β€œaction”, β€œname”: β€œStep”, β€œmethod”: β€œPOST”, β€œhref”: β€œActions” β€œcontent-format”: β€œapplication/tdlactions+json”, β€œparameters”:[ {β€œname”: β€œstepSize”, β€œdataType”: β€œfloat”}, {β€œname”: β€œtransitionTime”, β€œdataType”:”float”, β€œunits”: β€œs”}] β€œtemplate”: β€œ{ β€œstepSize”: β€œ$stepSize”, β€œtransTime”: β€œ$transitionTime” }”, β€œreturns”: [{β€œresponseCode”: β€œ201”, β€œresponseAction”: β€œsuccess” β€œparameters”: [{β€œtype”: β€œheader”, β€œname”: β€œLocation”, β€œtype”: β€œhref” β€œrel”: β€œactionInstance” }], ]} To Step the ColorTemperature of /light, POST a template containing stepSize and transition Time parameters to the resource at /light/ColorTemp/Actions. Expect a responseCode of 201 if success and expect to find an actionInstance resource pointed to by the header parameter named β€œLocation”.
  • 23. Hypertext Form for Move Action hypertext form at resource context = /light/ColorTemp: { β€œrel”: β€œaction”, β€œtype”: β€œaction”, β€œname”: β€œMove”, β€œmethod”: β€œPOST”, β€œhref”: β€œActions” β€œcontent-format”: β€œapplication/tdlactions+json”, β€œparameters”:[ {β€œname”: β€œmoveRate”, β€œdataType”: β€œfloat”, β€œunits”: β€œK/s”}] β€œtemplate”: β€œ{β€œrate”: β€œ$moveRate”}”, β€œreturns”: [{β€œresponseCode”: β€œ201”, β€œresponseAction”: β€œsuccess” β€œparameters”: [{β€œtype”: β€œheader”, β€œname”: β€œLocation”, β€œtype”: β€œhref” β€œrel”: β€œactionInstance” }], ]} To Move the ColorTemperature of /light, POST a template containing the moveRate parameter to the resource at /light/ColorTemp/Actions. Expect a responseCode of 201 if success and expect to find an actionInstance resource pointed to by the header parameter named β€œLocation”.
  • 24. β€’ Can be discovered by the application as the result of a gradual reveal process guided by an ontology, e.g. ColorTemperature control with ChangeValue control semantics β€’ The name can be rendered to the application based on discovered names populated from well known namespaces e.g. Schema.org β€’ Actions can be invoked by reusable handlers for well known data and control models β€’ Example serialization of an action and invocation using discovered names with values supplied from a scene controller: action= my_light.ColorTemperature.Change(targetValue=2900, TransitionTime=10) β€’ The hypermedia control generates this transaction: POST uri=/light/ColorTemp/Actions pl={β€œchangeTemp”: β€œ2900”, β€œtransTime”: β€œ10”} β€’ A success response contains the URI of the Action resource in the location header: 201 Created Location: ac3f5774 β€’ Execution of the action can be controlled through the Action resource: action.cancel() DELETE uri=/light/ColorTemp/Actions/ac3f5774 Application Interface Mapping
  • 25. Hypertext Link – CoAP + IPSO Binding hypertext link at resource context = /light { β€œrel”: β€œaction”, β€œhref”: β€œ3004/0”, β€œtype”: β€œactuator”, β€œname”: β€œColorTemperature” } β€œ/light has an action resource at the URI /light/3004/0 of type actuator named ColorTemperature”
  • 26. Hypertext Form – CoAP + IPSO Binding hypertext form for CoAP binding, resource context = /light/3004/0: { β€œrel”: β€œaction”, β€œtype”: β€œaction”, β€œname”: β€œChange”, β€œmethod”: β€œPOST”, β€œhref”: β€œ5052” β€œcontent-format”: β€œapplication/ipso+senml+json”, β€œparameters”:[ {β€œname”: β€œtargetValue”, β€œdataType”: β€œfloat”}, {β€œname”: β€œtransitionTime”, β€œdataType”:”float”, β€œunits”: β€œs”}] β€œtemplate”: β€œ[{β€œn”: β€œ5059”, β€œv”: β€œ$targetValue”} {β€œn”: β€œ5002”, β€œv”: β€œ$transitionTime”}]”, β€œreturns”: [{β€œresponseCode”: β€œ2.01”, β€œresponseAction”: β€œsuccess” β€œparameters”: [{β€œtype”: β€œheader”, β€œname”: β€œLocation”, β€œtype”: β€œhref” β€œrel”: β€œactionInstance” }], ]} To Change the ColorTemperature of /light, POST a template containing targetValue and transition Time parameters to the resource at /light/3004/0/5052. Expect a responseCode of 2.01 if success and expect to find an actionInstance resource pointed to by the header parameter named β€œLocation”
  • 27. β€’ Example serialization of an action and invocation using discovered names with values supplied from a scene controller: action= my_light.ColorTemperature.Change(targetValue=2900, TransitionTime=10) β€’ The IPSO + CoAP hypermedia control generates this request: POST uri=/light/3004/0/5052 pl=[{β€œn”:β€œ5059”,β€œv”:β€œ2900”},{β€œn”:β€œ5002”,β€œv”:β€œ10”}] β€’ A success response contains the URI of the Action resource in the location header: 2.01 Created Location: 17 β€’ Execution of the action can be controlled through the Action resource: action.cancel() DELETE uri=/light/3004/0/5052/17 Uniform Application Interface, Hypermedia Controls for IPSO + CoAP
  • 28. References β€’ [Fielding2000] http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm β€’ [Fielding2008] http://roy.gbiv.com/untangled/2008/rest-apis- must-be-hypertext-driven β€’ [WEBAPIS] Richardson, L. and M. Amundsen, "RESTful Web APIs”, O'Reilly, September 2013. β€’ [Hartke2015] https://tools.ietf.org/html/draft-hartke-core- apps-01 https://tools.ietf.org/html/draft-hartke-core-lighting- 00