reactive hypermedia

47
Reactive Hypermedia Kevin Swiber

Upload: kevin-swiber

Post on 19-Jun-2015

530 views

Category:

Technology


2 download

DESCRIPTION

Reactive Hypermedia is a style of API that promotes both client-server interactions and event-driven data streams. It was developed to solve the problems of massive scale introduced by the Internet of Things.

TRANSCRIPT

  • 1. Reactive HypermediaKevin Swiber

2. Its true. 3. I work on an open source platformfor the Internet of Things.http://zettajs.org 4. The World As WeKnow It 5. The most popular APIsare URL-first. 6. Client-server architectureis abundant. 7. Event-Driven Architectureis often in a silo. 8. We are modeling HTTP handlersas actions on controllers. 9. Change is Coming 10. We are shifting from fullservice to self service. 11. We are moving from fewand big to many and small. 12. We are progressing fromrigid to flexible. 13. DistributedQuestions 14. How do we allow clientsto access resourceshosted on any server? 15. How can API Resources offerevent-driven data streams? 16. How can we manage statein our API Resources? 17. How can we make resource transitionavailability a responsibility of theserver? 18. How do we gain greatercontrol over latency? 19. Constraints 20. Resource abstractionsmust be joyful to use. 21. Proxies are a commoncomponent in the architecture. 22. Clients may need to contend withresources that are not yet available. 23. Everything needs an API. 24. A New Approach 25. API responses mustrepresent state machines. 26. Event-driven design must runalongside tried and true client-server. 27. Multiple servers will beresponsible for processing logic. 28. Utilize reactiveprogramming. 29. Implementation 30. Model resources as finitestate machines.LED.prototype.init = function(config) {config.type('led').state('off').when('off', { allow: ['turn-on'] }).when('on', { allow: ['turn-off'] }).map('turn-on', this.turnOn).map('turn-off', this.turnOff);}; 31. Use a hypermedia type that canrepresent the state machine model. 32. Transitions are represented asaffordances in the message."actions": [{"name": "turn-on","method": "POST","href": ...,"fields": [{"name": "action","type": "hidden","value": "turn-on"}]}] 33. We need to consume anobject stream.links: [{title: pulse,rel: [http://rxapi.org/object-stream],href: ws://...}] 34. We need to consume anobject stream. wscat -c ws://...connected (press CTRL+C to quit)< {"topic":"heartbeat/1/pulse","timestamp":1411757412119,"data":61}< {"topic":"heartbeat/1/pulse","timestamp":1411757412620,"data":65}< {"topic":"heartbeat/1/pulse","timestamp":1411757413121,"data":69}< {"topic":"heartbeat/1/pulse","timestamp":1411757413622,"data":71}< {"topic":"heartbeat/1/pulse","timestamp":1411757414124,"data":66}< {"topic":"heartbeat/1/pulse","timestamp":1411757414626,"data":64}< {"topic":"heartbeat/1/pulse","timestamp":1411757415128,"data":68}< {"topic":"heartbeat/1/pulse","timestamp":1411757415629,"data":63}< {"topic":"heartbeat/1/pulse","timestamp":1411757416130,"data":65}< {"topic":"heartbeat/1/pulse","timestamp":1411757416631,"data":63} 35. Monitor resource eventsbefore taking action.links: [{title: logs,rel: [monitor,http://rxapi.org/object-stream],href: ws://...}] 36. Monitor resource eventsbefore taking action. wscat -c ws://...connected (press CTRL+C to quit)< {"topic":"led/2/logs","timestamp":1411809676901,"transition":"turn-on","input":[],"properties":{"id":"2","type":"led","name":null,"state":"on"}}< {"topic":"led/2/logs","timestamp":1411809677548,"transition":"turn-off","input":[],"properties":{"id":"2","type":"led","name":null,"state":"off"}}< {"topic":"led/2/logs","timestamp":1411809678483,"transition":"turn-on","input":[],"properties":{"id":"2","type":"led","name":null,"state":"on"}}< {"topic":"led/2/logs","timestamp":1411809679126,"transition":"turn-off","input":[],"properties":{"id":"2","type":"led","name":null,"state":"off"}} 37. We also need binary.links: [{rel: [http://rxapi.org/binary-stream],href: ws://...,type: video/mpeg,}] 38. We also need binary. wscat -c ws://...connected (press CTRL+C to quit)Q`rCEDDIp=`"3ss79:Yk}{` 5e`>9%J[K89z^> 8X Gp;WqXFh1{%O;72e,l{%`:kJfu^LV"u8GU* 39. We also need binary. wscat -c ws://...connected (press CTRL+C to quit) 40. Clients work! 41. Going Forward 42. Solve the producer-consumerproblem. 43. We need to do a best-effort docgeneration from state machines. 44. Build reactive clients.get(http://...).links().where({ rel, { contains: monitor }).subscribe(function(data) {console.log(Received:, data);}); 45. Make more. 46. Share. :) 47. Questions? [email protected] https://twitter.com/kevinswiber https://linkedin.com/in/kevinswiber https://github.com/kevinswiber