REST APIs for an Internet of Things
-
Upload
michael-koster -
Category
Internet
-
view
413 -
download
1
description
Transcript of REST APIs for an Internet of Things
![Page 1: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/1.jpg)
REST APIs for the
Internet Of Things
Michael J Koster Open Source Internet Of Things
Meetup 19 March 2014
![Page 2: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/2.jpg)
Resource oriented API
• Resource == web resource (URI) • Resources change state in response to what is being sensed
• Actuator changes state in response to web resource update
• Abstract data sources and sinks • REST API has 2 important characterisJcs for IoT use case…
![Page 3: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/3.jpg)
RepresentaJonal State Transfer
• Resource interacJon through exchange of representaJon of resource state
• E.g. a representaJon of the state of a temperature sensor might be “63.6”
• Convenient for applicaJon soTware to use read/write semanJcs to interact with resources
• Stateful resource representaJons => Stateless applicaJon soTware
![Page 4: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/4.jpg)
Based on Hypermedia
• Use of web links to locate resources of interest
• IoT needs machine-‐readable links that enable applicaJon soTware to discover things of interest
• Subset of web linking, semanJc web using relaJon/a\ribute
• Links encode metadata about the resource, e.g. type=‘temperature’, ct=‘applicaJon/json’
![Page 5: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/5.jpg)
Web Linking for IoT
• Links are managed in 2 ways • Object encapsulaJon: self-‐describing objects have links associated with endpoint, e.g. ./well-‐known/core
• Resource Directory: Directories and Catalogs of links, stored at well-‐known locaJons, that point to resources and to other catalogs
![Page 6: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/6.jpg)
Web Linking for IoT
• Links can be registered with a Resource Directory when sensors are brought online
• A crawler can discover links at ./well-‐known/core locaJons and populate catalogs
• ApplicaJon soTware can discover resources by a\ribute, e.g. query using type=‘temperature’, units=‘celsius’, locaJon=‘outdoor’ etc.
• System returns a set of links matching the query a\ributes
![Page 7: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/7.jpg)
CoAP
• Part of IPV6 for Constrained Resource Environments (CoRE)
• IoT oriented REST API mapped to an efficient binary protocol
• End devices can have both client and server roles, can also communicate directly
• Resource representaJon e.g. ‘applicaJon/json’, is negoJated as in h\p protocol
![Page 8: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/8.jpg)
CoAP
• Observe opJon for long-‐term event stream response to GET, asynchronous updates
• Web linking using IETF standard core-‐link-‐format (RFC 6690)
• Resource discovery using ./well-‐known/core or external Resource Directory
![Page 9: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/9.jpg)
HTTP/REST
• HTTP and REST is useful for most web applicaJons, services, and gateways
• Uses web callbacks, websockets, HTTP PUT for asynchronous updates
• Links in JSON, Link-‐format, Hypercat, linked data
• Well defined CoAP-‐to-‐HTTP proxy pa\erns, standard middleware
![Page 10: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/10.jpg)
Hybrid system
• It’s possible to use REST for resource discovery and other stateful interacJons, and messaging e.g. MQTT for asynchronous updates
• Various methods to bind message endpoints to REST resources
• ApplicaJon soTware can easily use both REST API and event handler interfaces like onUpdate
• IoT Toolkit uses observers to bind
![Page 11: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/11.jpg)
Standards and SoTware • CoAP h\ps://datatracker.iel.org/doc/draT-‐iel-‐core-‐coap/
• CoRE link-‐format h\p://tools.iel.org/html/rfc6690
• CoRE Observe h\ps://datatracker.iel.org/doc/draT-‐iel-‐core-‐observe/
• CoRE Resource Directory h\ps://tools.iel.org/html/draT-‐iel-‐core-‐resource-‐directory-‐00
• Hypercat h\p://wiki.1248.io/doku.php?id=hypercat
![Page 12: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/12.jpg)
IoT Toolkit Interoperability Demo
smartobjectservice.com
Node-‐RED
Node-‐RED
![Page 13: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/13.jpg)
MQTT Observer
MQTT Broker
REST Endpoint ObservableProperty
mq\Observer
PUT GET
Publish from data producer
Publish From REST API
Publish to Other Subscribers
SUB Publish to REST API
Connects REST Resource to MQTT Topic Publish and Subscribe
![Page 14: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/14.jpg)
MQTT Observer
MQTT Broker
REST Endpoint ObservableProperty
mq\Observer
PUT GET
Publish from data producer
Publish From REST API
Publish to Other Subscribers
SUB Publish to REST API
Publisher Publishes REST Resource updates to the broker
![Page 15: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/15.jpg)
MQTT Observer
MQTT Broker
REST Endpoint ObservableProperty
mq\Observer
PUT GET
Publish from data producer
Publish From REST API
Publish to Other Subscribers
SUB Publish to REST API
Subscriber Makes last published data available at the REST endpoint
![Page 16: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/16.jpg)
MQTT Observer
MQTT Broker
REST Endpoint ObservableProperty
mq\Observer
PUT GET
Publish from data producer
Publish From REST API
Publish to Other Subscribers
SUB Publish to REST API
Pub+Sub Repeats data updates in both direcJons
![Page 17: REST APIs for an Internet of Things](https://reader034.fdocuments.in/reader034/viewer/2022051817/5479f8d1b4af9fef158b49b6/html5/thumbnails/17.jpg)
MQTT Bridge to mulJple REST endpoints
MQTT Broker
REST Endpoint ObservableProperty
mq\Observer
PUT GET
Publish from data producer
Publish to Other Subscribers
REST Endpoint ObservableProperty
mq\Observer
PUT GET