5 Ways to Make Your Mobile Apps Faster with the Chatter REST API

At Salesforce.com, we love our mobile apps and strive to bring you the best possible user experience on them. A big part of great user experience is responsiveness—nobody wants a sluggish app. We’ve learned that using an API designed for mobile consumption is essential when dealing with the reality of high latency in mobile networks and low processing power in mobile devices (particularly older ones). In this article, we’d like to highlight some of the mobile-friendly features that we’ve built into the public Chatter REST API, which is used by our Chatter Mobile apps and countless third-party web, desktop, and mobile applications.

Simple and Complete Responses

The Chatter REST API is a presentation layer REST API. When you issue a request, what comes back is a representation that’s easy to consume when you’re building a UI. For example, if you want to display a user’s Chatter news feed in your app, it only takes a single call to the /chatter/feeds/news/me endpoint to get everything you need to render a page—it returns the feed items, comments, likes, information about the users, and much more. Minimizing the number of network round trips is essential for mobile app performance. The more complete the representation is, the fewer round trips you need to make.

Property filtering

There’s a tradeoff in providing so much information in a response. If some of the data isn’t needed, it’s overhead: it consumes bandwidth and processing power. To address this, we introduced the ability to filter response bodies in v27.0 of the Chatter REST API. This feature allows you to specify exactly which properties you require in the representation. For example, if you only want to include the bodies of feed items within a feed, you can make this request for a compact response:

GET /chatter/feeds/news/me/feed-items?include=/items/feedItem/body

You can also specify properties to exclude. For example, if you have no need for the clientInfo property of a feed item, you can exclude it from the response with:

GET /chatter/feeds/news/me/feed-items?exclude=/items/feedItem/clientInfo

These examples filter a single property, but you can also filter multiple properties.

Generic batching

It’s not always possible for us to provide everything you need to build a UI screen in a single API call. In v28.0 of the Chatter REST API, we introduced a new endpoint, /connect/batch, that allows you to combine multiple subrequests into a single request. Our mobile development team loves using this feature to minimize the number of round trips their apps require.

Taking an example from our API documentation, here’s how to like a Chatter feed item (the first subrequest) and then get the total number of likes on that feed item. Notice that the second subrequest uses an inclusion filter to get only the data it needs, as described above.

Batching for specific object types

The Chatter REST API also offers optimized batch endpoints for files, group memberships, groups, motifs, and users. They allow you to specify a list of IDs and get information about them in one call—the data is “bulk loaded”, which means that it’s retrieved optimally from the database. Bulk loading is much faster than issuing individual calls for each ID, even if they’re done in a generic batch. Here’s an example that shows how to get information about three Chatter groups:

GET /chatter/groups/batch/0F9B000000000W2,0F9B000000005Px,0F9B000000006Tu

Paged Collections

Many of our endpoints can return a very large amount of data that a client doesn’t need. Examples include getting a user’s news feed and querying for information about the Chatter groups in an organization. Rather than returning everything, we return paged data and use opaque tokens for going to the next page and the previous page. Clients can specify the page size for greater flexibility, and we’ve chosen reasonable defaults such as 25 feed items per page.

Try the Chatter REST API

These are some of the ways the Chatter REST API team is enabling mobile app developers to improve the responsiveness of their apps, and we’re working on many more! Remember that even though these features are particularly well-suited for mobile apps, they’re generally applicable and have benefits for traditional web and desktop apps too. Everybody loves a performance gain.