The UK Department of Trade and Investment regularly runs trade missions to the Bay Area; yesterday the UK TI ‘Cloud Mission’, a group of British entrepreneurs working with cloud technology, visited us here at salesforce.com, and I had the pleasure of presenting our Social Enterprise Platform (database.com, Force.com and Heroku) to them, and chatting with some of them about their companies and technology.
Among the delegates was Max Williams, CEO of Pusher, a startup providing real-time updates (in the sense of WebSockets) as-a-service, and Max encouraged me to try Pusher out. How could I resist? Since there’s already a Heroku Pusher add-on, I decided to try pushing events from Apex code running on Force.com.
Since the Apex implementation comprises all of 51 lines of code, rather than spinning up a GitHub project, I decided to just post it here, since it’s a nice little example of calling a REST API from Apex.
So, here’s the browser code, in a Visualforce Page:
A real app would do something more interesting with the data than just pop up an alert, but you get the idea, I’m sure 🙂
The Apex Pusher class:
Apex code to invoke the Pusher class:
And proof that it works 🙂
Although I just pushed a string here, you could just as easily push JSON data:
So, go give Pusher a spin, and let us know in the comments if you’ve implemented an interesting API from Apex recently.