GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - sethmcl/notifyit: A simple PubSub tool which allows you to publish events via an HTTP POST interface, and subscribe to events via a socket.io connection.

BranchesTags
Open more actions menu

Latest commit

 

History

5 Commits
5 Commits

Folders and files

NameName
Last commit message
Last commit date
bin
bin
 
 
css
css
 
 
js
js
 
 
tests
tests
 
 
views
views
 
 
.gitignore
.gitignore
 
 
LICENSE.TXT
LICENSE.TXT
 
 
README.md
README.md
 
 
notifyit.js
notifyit.js
 
 
package.json
package.json
 
 

Repository files navigation

#NotifyIt

This is a simple PubSub tool which allows you to publish events via an HTTP POST interface, and subscribe to events via a socket.io connection.

##Pre-reqs To use this tool, you'll need to have node.js (v0.4 or greater) and npm installed. I've tested the tool on OSX and Linux, but it should work fine on Windows as well.

##Install

git clone git://github.com/sethmcl/notifyit.git
cd notifyit
npm install

Alternatively, install directly with npm:

npm install notifyit

##Usage

To start the server, run:

$ bin/notifyit [port]

You can optionally specify a port. If not port is specified, the default port of 2012 will be used.

##Publishing Events To publish an event, post to the /pub endpoint on the server. For example to publish an event called "new-data" on the "test" channel, you could POST something like this:

$ curl http://localhost:2012/pub/test/new-data -d "{\"name\":\"Seth\"}" -H "Content-Type:application/json" -v

By specifying the Content-Type, NotifyIt will attempt to parse the request body as JSON. If the parsing fails (due to malformed JSON), then the event will not be published and you will receive a 500 HTTP response.

If you do not specify a content type, NotifyIt will assume the data is simple text. Let's publish an event called "connect" on the "test" channel:

$ curl http://localhost:2012/pub/test/connect -d "name=Seth" -v

Try running these commands - you will see status output in the console where you are running the server.

##Subscribing to Events Subscribing to events is pretty straightforward. Include the socket.io client library on your page or node.js script, and then subscribe to events. Example:

var socket = io.connect('http://localhost:2012');
socket.on('test:new-data', function(e) {
  console.log( e.channel ); // Channel name, e.g., 'test'
  console.log( e.event );   // Event name, e.g., 'new-data'
  console.log( e.data );    // Data, e.g., 'name:Seth'. If event data was published as JSON, then this will be an object.
}

Alternatively, you can subscribe to the 'all' event to receive all events:

var socket = io.connect('http://localhost:2012');
socket.on('all', function(e) {
  console.log( e.channel ); // Channel name, e.g., 'test'
  console.log( e.event );   // Event name, e.g., 'new-data'
  console.log( e.data );    // Data, e.g., 'name:Seth'. If event data was published as JSON, then this will be an object.
}

##Sample App To see this in action, start the server:

$ bin/notifyit

Then open a browser and go to http://localhost:2012.

Finally, publish a sample event with a curl command:

$ curl http://localhost:2012/pub/test/connect -d "name=Seth"

You should see the event disaplayed in the browser.

##Running the Unit Tests

If you have not installed the nodeunit command before, please run these commands to build:

$ cd node_modules/nodeunit
$ sudo make install
$ cd ../../

To execute the tests, run this command from the repository root:

$ nodeunit tests/

About

A simple PubSub tool which allows you to publish events via an HTTP POST interface, and subscribe to events via a socket.io connection.

Resources

Readme
Apache-2.0 license
Activity

Stars

10 stars

Watchers

3 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.