Publishing events

Pusher provides a REST API that allows your server to send verified events to your clients. These are signed with your secret key, and can therefore be trusted by all clients.

We have a number of server libraries that make sending messages by triggering events really easy. The fundamentals are that a event must be triggered on a channel with an event name. The message itself can be in any format however we recommend using serialised JSON as it keeps message sizes down and JSON can easily be consumed by any technology.

In the examples below an event called test_event is being triggered on a channel named test-channel. The messages payload ultimately ends up as a simple JSON messages {"hello":"world"}.

Event names (and the channels they are sent to) can only contain characters which are alphanumeric, '-' or '_'.

# Using https://github.com/pusher/pusher-gem Pusher.app_id = 'APP_ID' Pusher.key = 'API_KEY' Pusher.secret = 'SECRET_KEY' class HelloController < ApplicationController def hello Pusher['test-channel'].trigger('test_event', '{"hello":"world"}') end end require('Pusher.php'); $pusher = new Pusher($key, $secret, $app_id); $pusher->trigger('test-channel', 'test_event', '{"hello":"world"}'); var request = new ObjectPusherRequest("test_channel", "my_event", new { hello = "world" }); var provider = new PusherProvider(appId, appKey, appSecret); provider.Trigger(request);

The message should always be encoded as UTF-8. Upon receipt of data which is not valid UTF-8, the API will return a 400 response code.