Last active
November 26, 2019 19:27
-
-
Save nuria/1c2f251810ac8d5df10c753f5d64f78a to your computer and use it in GitHub Desktop.
Event Streams consumption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the EventStreams RecentChange stream endpoint | |
var url = 'https://stream.wikimedia.org/v2/stream/recentchange'; | |
// Use EventSource (available in most browsers, or as an | |
// npm module: https://www.npmjs.com/package/eventsource) | |
// to subscribe to the stream. | |
var recentChangeStream = new EventSource(url); | |
// Print each event to the console | |
recentChangeStream.onmessage = function(message) { | |
//Parse the message.data string as JSON. | |
var event = JSON.parse(message.data); | |
console.log(event); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment