SlideShare a Scribd company logo
Using Communication and 
Messaging API in The HTML5 
World 
Gil Fink 
CEO, sparXys 
@gilfink, http://www.gilfink.net
Agenda 
• HTML5: Recap 
• HTML5 Messaging APIs 
• HTML5 Communication APIs 
• Q&A 
• Summary
HTML5: Recap 
• HTML5 ~= HTML + CSS3 + new JavaScript API 
• The present and future of the web 
• W3C Recommendation!
What’s Under the HTML5 
Umbrella?
Communication and Messaging
Cross-Document Messaging 
• Simple API to send and receive in-window 
messages 
• Send messages using the postMessage function 
• Wire handlers to the message event 
6 
window.postMessage(message, domain); 
window.addEventListener("message", function () { 
// do something 
}, false);
DEMO 
Cross-Document Messaging 
Web Worker
Web Application APIs Support 
– Cross-Document Messaging 
http://caniuse.com
Cross-Origin Resource Sharing 
(CORS) 
• Browsers prevent cross-domain JavaScript requests 
• CORS enables cross-domain requests as long as: 
o Response includes Access-Control-Allow-Origin header 
o XMLHttpRequest supports CORS 
• XDomainRequest in IE8 and IE9
CORS – Client Side 
var xhr = new XMLHttpRequest(); 
xhr.open(“get”, url, true); 
xhr.onload = function () { 
// instead of using onreadystatechange 
} 
xhr.send();
CORS – Client Side API 
• Functions: 
o abort() – stops a request that is already in progress 
o send() – sends a request to the server 
• Event handlers: 
o onerror – handles request errors 
o onload – handles request success
CORS – Access Control Flow 
• Client sends ‘Access-Control’ headers during 
request preflight 
o Using the OPTIONS HTTP request 
• Server checks whether the requested resource is 
allowed 
• Client checks the preflight response and decides 
whether to allow the request
CORS – Server Side 
• Use Access-Control headers to allow 
o Origin – Specific request URI 
o Method – request method (GET, POST and etc.) 
o Headers – optional custom headers 
o Credentials – request credentials
DEMO 
CORS
Web Application APIs Support 
– CORS 
http://caniuse.com
Server-Sent Events 
• Enables servers to push data over HTTP using push 
protocols 
• Use the EventSource JavaScript API 
var source = new EventSource(url); 
source.onmessage = function (e) { 
console.log(e.data); 
}
Server-Sent Events - Server 
• Strict server protocol: 
data: This is a message. 
event: add 
data: 73857293 
• Response content type should be text/event-stream 
• Keeps the connection open
DEMO 
Server-Sent Events
Web Application APIs Support 
– Server-Sent Events 
http://caniuse.com
Real Time Web?
Existing Solutions
Web Sockets 
• Bidirectional communications channels, over a 
single TCP socket 
• Don’t allow raw access to the underlying network 
• Can replace old techniques such as: 
o Forever frames 
o Long-polling/comet
Web Sockets – Client Request 
• The client sends a WebSocket handshake request 
GET /chat HTTP/1.1 
Host: server.example.com 
Upgrade: websocket 
Connection: Upgrade 
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== 
Sec-WebSocket-Origin: http://example.com 
Sec-WebSocket-Protocol: chat, superchat
Web Sockets – Server Response 
• The server responses with a WebSocket handshake 
response 
HTTP/1.1 101 Switching Protocols 
Upgrade: websocket 
Connection: Upgrade 
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= 
Sec-WebSocket-Protocol: chat
Web Sockets – API 
• Create a WebSocket object using a URL 
• Use the WebSocket object’s built-in events: 
o onopen – fired when a web socket has opened 
o onmessage – fired when a message has been received 
o onclose – fired when a web socket has been closed
DEMO 
Web Sockets
Web Application APIs Support 
– Web Sockets 
http://caniuse.com
Questions?
Summary 
• HTML5 is a W3C recommendation 
• In this session we explored communication and 
messaging APIs 
• You have a lot more to cover
Resources 
• APIs specs – 
http://www.w3.org/TR/html5/comms.html 
http://www.w3.org/TR/cors/ 
http://www.w3.org/TR/eventsource/ 
http://www.w3.org/TR/websockets/ 
• My Blog – http://www.gilfink.net 
• Follow me on Twitter – @gilfink
Thank You!

More Related Content

What's hot

Websockets at tossug
Websockets at tossugWebsockets at tossug
Websockets at tossug
clkao
 

What's hot (20)

Web Servers(IIS, NGINX, APACHE)
Web Servers(IIS, NGINX, APACHE)Web Servers(IIS, NGINX, APACHE)
Web Servers(IIS, NGINX, APACHE)
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with java
 
Websockets at tossug
Websockets at tossugWebsockets at tossug
Websockets at tossug
 
HTTP/2 Prioritization
HTTP/2 PrioritizationHTTP/2 Prioritization
HTTP/2 Prioritization
 
How fast is it?
How fast is it?How fast is it?
How fast is it?
 
Web sockets in Java
Web sockets in JavaWeb sockets in Java
Web sockets in Java
 
Http/2
Http/2Http/2
Http/2
 
Resource Prioritization
Resource PrioritizationResource Prioritization
Resource Prioritization
 
Web sockets Introduction
Web sockets IntroductionWeb sockets Introduction
Web sockets Introduction
 
Server side
Server sideServer side
Server side
 
HTTP - The Protocol of Our Lives
HTTP - The Protocol of Our LivesHTTP - The Protocol of Our Lives
HTTP - The Protocol of Our Lives
 
Real Time Recommendations Using WebSockets and Redis - Ninad Divadkar, Inuit
Real Time Recommendations Using WebSockets and Redis - Ninad Divadkar, InuitReal Time Recommendations Using WebSockets and Redis - Ninad Divadkar, Inuit
Real Time Recommendations Using WebSockets and Redis - Ninad Divadkar, Inuit
 
Revisiting HTTP/2
Revisiting HTTP/2Revisiting HTTP/2
Revisiting HTTP/2
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
 
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
Server Sent Events, Async Servlet, Web Sockets and JSON; born to work together!
 
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
HTTPS: What, Why and How (SmashingConf Freiburg, Sep 2015)
 
ZN27112015
ZN27112015ZN27112015
ZN27112015
 
Server architecture
Server architectureServer architecture
Server architecture
 
Asynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and JavaAsynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and Java
 
signalr
signalrsignalr
signalr
 

Similar to Using Communication and Messaging API in the HTML5 World

HTML5/JavaScript Communication APIs - DPC 2014
HTML5/JavaScript Communication APIs - DPC 2014HTML5/JavaScript Communication APIs - DPC 2014
HTML5/JavaScript Communication APIs - DPC 2014
Christian Wenz
 

Similar to Using Communication and Messaging API in the HTML5 World (20)

Using communication and messaging API in the HTML5 world - GIl Fink, sparXsys
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsysUsing communication and messaging API in the HTML5 world - GIl Fink, sparXsys
Using communication and messaging API in the HTML5 world - GIl Fink, sparXsys
 
Ch 3: Web Application Technologies
Ch 3: Web Application TechnologiesCh 3: Web Application Technologies
Ch 3: Web Application Technologies
 
HTML5/JavaScript Communication APIs - DPC 2014
HTML5/JavaScript Communication APIs - DPC 2014HTML5/JavaScript Communication APIs - DPC 2014
HTML5/JavaScript Communication APIs - DPC 2014
 
CNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application TechnologiesCNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application Technologies
 
2. application layer
2. application layer2. application layer
2. application layer
 
Web Real-time Communications
Web Real-time CommunicationsWeb Real-time Communications
Web Real-time Communications
 
CNIT 129S: Ch 3: Web Application Technologies
CNIT 129S: Ch 3: Web Application TechnologiesCNIT 129S: Ch 3: Web Application Technologies
CNIT 129S: Ch 3: Web Application Technologies
 
DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2DDD Melbourne 2014 security in ASP.Net Web API 2
DDD Melbourne 2014 security in ASP.Net Web API 2
 
Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15Websocket vs SSE - Paris.js - 24/06/15
Websocket vs SSE - Paris.js - 24/06/15
 
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleJUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
 
Websocket
WebsocketWebsocket
Websocket
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
 
Building real-time-collaborative-web-applications
Building real-time-collaborative-web-applicationsBuilding real-time-collaborative-web-applications
Building real-time-collaborative-web-applications
 
.NET Conf 2022 - Networking in .NET 7
.NET Conf 2022 - Networking in .NET 7.NET Conf 2022 - Networking in .NET 7
.NET Conf 2022 - Networking in .NET 7
 
The ASP.NET Web API for Beginners
The ASP.NET Web API for BeginnersThe ASP.NET Web API for Beginners
The ASP.NET Web API for Beginners
 
Unit v
Unit v Unit v
Unit v
 
Web-01-HTTP.pptx
Web-01-HTTP.pptxWeb-01-HTTP.pptx
Web-01-HTTP.pptx
 
API Testing. Streamline your testing process.
API Testing. Streamline your testing process.API Testing. Streamline your testing process.
API Testing. Streamline your testing process.
 
Http - All you need to know
Http - All you need to knowHttp - All you need to know
Http - All you need to know
 
SFDC Outbound Integrations
SFDC Outbound IntegrationsSFDC Outbound Integrations
SFDC Outbound Integrations
 

More from Gil Fink

More from Gil Fink (20)

Becoming a Tech Speaker
Becoming a Tech SpeakerBecoming a Tech Speaker
Becoming a Tech Speaker
 
Web animation on steroids web animation api
Web animation on steroids web animation api Web animation on steroids web animation api
Web animation on steroids web animation api
 
The Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has ArrivedThe Time for Vanilla Web Components has Arrived
The Time for Vanilla Web Components has Arrived
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Stencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has ArrivedStencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has Arrived
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 
Being a tech speaker
Being a tech speakerBeing a tech speaker
Being a tech speaker
 
Working with Data in Service Workers
Working with Data in Service WorkersWorking with Data in Service Workers
Working with Data in Service Workers
 
Demystifying Angular Animations
Demystifying Angular AnimationsDemystifying Angular Animations
Demystifying Angular Animations
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angular
 
Redux data flow with angular
Redux data flow with angularRedux data flow with angular
Redux data flow with angular
 
Who's afraid of front end databases?
Who's afraid of front end databases?Who's afraid of front end databases?
Who's afraid of front end databases?
 
One language to rule them all type script
One language to rule them all type scriptOne language to rule them all type script
One language to rule them all type script
 
End to-end apps with type script
End to-end apps with type scriptEnd to-end apps with type script
End to-end apps with type script
 
Web component driven development
Web component driven developmentWeb component driven development
Web component driven development
 
Web components
Web componentsWeb components
Web components
 
Redux data flow with angular 2
Redux data flow with angular 2Redux data flow with angular 2
Redux data flow with angular 2
 
Biological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSBiological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJS
 
Who's afraid of front end databases
Who's afraid of front end databasesWho's afraid of front end databases
Who's afraid of front end databases
 

Recently uploaded

How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 

Recently uploaded (20)

In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 

Using Communication and Messaging API in the HTML5 World

  • 1. Using Communication and Messaging API in The HTML5 World Gil Fink CEO, sparXys @gilfink, http://www.gilfink.net
  • 2. Agenda • HTML5: Recap • HTML5 Messaging APIs • HTML5 Communication APIs • Q&A • Summary
  • 3. HTML5: Recap • HTML5 ~= HTML + CSS3 + new JavaScript API • The present and future of the web • W3C Recommendation!
  • 4. What’s Under the HTML5 Umbrella?
  • 6. Cross-Document Messaging • Simple API to send and receive in-window messages • Send messages using the postMessage function • Wire handlers to the message event 6 window.postMessage(message, domain); window.addEventListener("message", function () { // do something }, false);
  • 8. Web Application APIs Support – Cross-Document Messaging http://caniuse.com
  • 9. Cross-Origin Resource Sharing (CORS) • Browsers prevent cross-domain JavaScript requests • CORS enables cross-domain requests as long as: o Response includes Access-Control-Allow-Origin header o XMLHttpRequest supports CORS • XDomainRequest in IE8 and IE9
  • 10. CORS – Client Side var xhr = new XMLHttpRequest(); xhr.open(“get”, url, true); xhr.onload = function () { // instead of using onreadystatechange } xhr.send();
  • 11. CORS – Client Side API • Functions: o abort() – stops a request that is already in progress o send() – sends a request to the server • Event handlers: o onerror – handles request errors o onload – handles request success
  • 12. CORS – Access Control Flow • Client sends ‘Access-Control’ headers during request preflight o Using the OPTIONS HTTP request • Server checks whether the requested resource is allowed • Client checks the preflight response and decides whether to allow the request
  • 13. CORS – Server Side • Use Access-Control headers to allow o Origin – Specific request URI o Method – request method (GET, POST and etc.) o Headers – optional custom headers o Credentials – request credentials
  • 15. Web Application APIs Support – CORS http://caniuse.com
  • 16. Server-Sent Events • Enables servers to push data over HTTP using push protocols • Use the EventSource JavaScript API var source = new EventSource(url); source.onmessage = function (e) { console.log(e.data); }
  • 17. Server-Sent Events - Server • Strict server protocol: data: This is a message. event: add data: 73857293 • Response content type should be text/event-stream • Keeps the connection open
  • 19. Web Application APIs Support – Server-Sent Events http://caniuse.com
  • 22. Web Sockets • Bidirectional communications channels, over a single TCP socket • Don’t allow raw access to the underlying network • Can replace old techniques such as: o Forever frames o Long-polling/comet
  • 23. Web Sockets – Client Request • The client sends a WebSocket handshake request GET /chat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Sec-WebSocket-Origin: http://example.com Sec-WebSocket-Protocol: chat, superchat
  • 24. Web Sockets – Server Response • The server responses with a WebSocket handshake response HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= Sec-WebSocket-Protocol: chat
  • 25. Web Sockets – API • Create a WebSocket object using a URL • Use the WebSocket object’s built-in events: o onopen – fired when a web socket has opened o onmessage – fired when a message has been received o onclose – fired when a web socket has been closed
  • 27. Web Application APIs Support – Web Sockets http://caniuse.com
  • 29. Summary • HTML5 is a W3C recommendation • In this session we explored communication and messaging APIs • You have a lot more to cover
  • 30. Resources • APIs specs – http://www.w3.org/TR/html5/comms.html http://www.w3.org/TR/cors/ http://www.w3.org/TR/eventsource/ http://www.w3.org/TR/websockets/ • My Blog – http://www.gilfink.net • Follow me on Twitter – @gilfink