The Force.com REST API has seen incredible adoption since it became generally available just two releases ago in Spring ’11, and the Streaming API, while still a pilot feature, looks set to follow the same curve. There are enhancements and tweaks to both in Winter ’12 – here are the details…

As Sandeep mentioned the other day, while the REST API has supported upload of binary data since its inception, the maximum blob size has been limited to 50 MB (after base64 encoding). Winter ’12 brings the ability to upload blobs of up to 500 MB via multipart messages. The multipart syntax is quite straightforward, and familiar to anyone who has looked at the raw source of email messages:

--boundary_string
Content-Disposition: form-data; name="entity_document";
Content-Type: application/json

{  
    "Description" : "Marketing brochure for Q1 2011",
    "Keywords" : "marketing,sales,update",
    "FolderId" : "005D0000001GiU7",
    "Name" : "Marketing Brochure Q1",
    "Type" : "pdf"
}

--boundary_string
Content-Type: application/pdf
Content-Disposition: form-data; name="Body"; filename="2011Q1MktgBrochure.pdf"

Binary data goes here.

--boundary_string--

See the pre-release documentation for full details.

Turning to the Streaming API, the Winter ’12 iteration of the pilot brings some changes. One important change for anyone who has been working with Streaming in Summer ’11 is that the session token is now sent as an OAuth token in the HTTP Authorization header, rather than as a cookie.

Authorization: OAuth sessionId

This change brings Streaming into line with the REST API, and allows easier integrations, since JavaScript running in the browser is free to set the Authorization header, while cookies are off-limits.

Another key change in Winter ’12 is that subscribing applications must prefix the PushTopic name with "/topic/".

The net effect of these changes is that a JavaScript app using the jQuery CometD binding now connects and subscribes for updates thus:

var cometdUrl = 'https://' + window.location.hostname + '/cometd/23.0/';
var auth = 'OAuth {!$Api.Session_ID}';

$.cometd.init({ 
    url: cometdUrl,
    requestHeaders: { Authorization: auth }
});

$.cometd.subscribe('/topic/AccountTopic', function(message) {
    // do something with the message
});

The final significant change in Winter ’12 is that session timeouts are now restarted with every operation on the connection, rather than sessions having a maximum duration, regardless of activity. Again, full details can be found in the pre-release documentation.

One aspect of the Streaming API that remains the same in Winter ’12 is that it is still in limited pilot. If you want to get to grips with Streaming on Force.com, head on over to the Streaming API page and get with the program!

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS