-
Notifications
You must be signed in to change notification settings - Fork 4
Javascript Client
Jason Dentler edited this page Jul 20, 2011
·
3 revisions
This is a brief explanation of the Javascript client API, Hermes.js, which closely resembles the C# API. Hermes.js differs from the C# library in one important way: All REST requests are performed asyncronously.
From the JsClient project:
- Hermes.js
- RestClient.js
- jquery.json2xml.js
- jquery.jfeed.js (slightly modified to work with Hermes)
From MSDN
- Rx.js
- Rx.jQuery.js Due to EULA restrictions, these are not included.
From any official source:
- jQuery (tested with v1.6.2)
- Some knowledge of jQuery promises.
var hermesUrl = 'http://server.domain.com/Hermes';
new HermesClient(url).TryCreateGroup('Chat Server', 'Website chat group')
.TryCreateTopic('Weather', 'Weather alerts')
.PollFeed(500)
.Subscribe(function (message) {
console.log('Weather alert: ' + message);
});
var hermesUrl = 'http://server.domain.com/Hermes';
var topicProxy = new HermesClient(hermesUrl)
.TryCreateGroup('Chat Server', 'Website chat group')
.TryCreateTopic('Weather', 'Weather alerts');
topicProxy.PostStringMessage('Hurricane Warning');
Here's an example of publishing a JSON message:
var hermesUrl = 'http://server.domain.com/Hermes';
var topicProxy = new HermesClient(hermesUrl)
.TryCreateGroup('ShoppingCart','')
.TryCreateTopic('Cart abcdef1234567890');
var message = {Type: 'ItemAddedEvent', ItemId: '123456', Quantity: 2};
var data = JSON.stringify(message);
topic.PostMessage(data, 'application/json');
- Hermes Client: This is the entry point for the client API.
- Group: Represents a Hermes group on the server.
- Group Proxy: A promise for a Group, and provides most Group methods.
- Topic: Represents a Hermes topic on the server.
- Topic Proxy: A promise for a Topic, and provides most Topic methods.
- Observable: A standard Reactive Extensions for Javascript Observable. Refer to the Rx documentation for more information.
- Subscription: Used internally to manage a topic subscription.
- RestClient: Used internally to communicate with the Hermes REST service.