Database Reference
In-Depth Information
var counters = require('./lib/counters');
app.set("counters",counters);
app.get('/api/v1/incr/:counter', function(req,res) {
counters.increment(req.params.counter,req.query.amount,
function() {
res.end("OK\n");
});
});
app.get('/api/v1/counter/:counter',function(req,res) {
counters.get(req.params.counter,function(err,data) {
res.end(data+"\n");
});
});
app.get('/api/v1/state',function(req,res) {
counters.state(function(err,data) {
for(var counter in data) {
res.write(counter+": "+data[counter]+"\n");
}
res.end();
});
});
Server Sent Events
Server Sent Events (SSEs) were added to the HTML5 specification by the
Web Hypertext Application Technology Working Group (WHATWG).
Originally introduced in 2006, the SSE protocol uses HTTP as its transport
mechanism with the text/event-stream Content Type. The basic
response is a line prefixed with data: and ending with \n\n (two newline
characters). A multiline response is allowed by only using a single newline,
but it still starts with the data: prefix. The web server may set an optional
retry timeout, event, and an ID field using the retry: , event: , and id:
prefixes, respectively. A complete response looks something like this:
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/event-stream
Cache-Control: no-cache
Search WWH ::




Custom Search