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.

Message size limits

The data content of events must be smaller than 10kB.

When using the REST API, the POST body corresponds to the event data. If you attempt to POST a larger body you will receive a 413 error code (see error codes). If you have a use case which requires a larger messages size please get in touch.

Error codes

  • 400 Bad Request - The message should always be encoded as UTF-8.
  • 403 Forbidden - You have exceeded your daily message quota.
  • 413 Request Entity Too Large - Message size is greater than allowed size for the application. Default for this is 10Kb.

Example

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 = 'APP_KEY' Pusher.secret = 'APP_SECRET' class HelloController < ApplicationController def hello Pusher.trigger('test-channel', 'test_event', { :hello => 'world' }) end end require('Pusher.php'); $pusher = new Pusher($key, $secret, $app_id); $pusher->trigger('test-channel', 'test_event', array( 'hello' => 'world' ) ); var request = new ObjectPusherRequest("test_channel", "my_event", new { hello = "world" }); var provider = new PusherProvider(appId, appKey, appSecret); provider.Trigger(request);

Have you tried using the search to find what you’re after? If you still have a question then get in touch with us and let us help you out.