Of all the technologies in the Spring ’11 release preview, one of the most eagerly awaited has been the Force.com REST API – a lightweight alternative to the existing SOAP web service interface that really opens up Force.com to any platform, any language and any device. A quick glance at the REST API discussion board shows that it’s been well road-tested during its developer preview over the past three months, with questions from developers working with technologies ranging from PHP to Java ME.
I covered the basics of the REST API in the getting started guide back in October, showing how a Java Servlet can easily query, create, retrieve, update and delete data in Force.com, with cookbook recipes covering the same ground in PHP and Ruby. REST‘s model of a uniform HTTP interface to a set of URLs makes it a snap to get up and running, while OAuth 2.0 provides a secure route for user authentication that enhances privacy by keeping user passwords out of your web application.
As well as the functionality already seen in the developer preview, it’s worth mentioning a couple of new features in the Spring ’11 pipeline – HTTP 1.1 compression and upsert. Compression simply allows a client to indicate that a request payload is compressed via the Content-Encoding header, and that it can accept compressed content via the Accept-Encoding HTTP header. Full details are in the pre-release Force.com REST API Developer’s Guide. I haven’t run any benchmarks yet, but I would expect to see worthwhile performance gains, particularly in relatively low bandwidth environments such as mobile applications.
If you haven’t yet come across the ‘upsert‘ operation, it’s simply a mechanism for updating or inserting data depending on whether or not a record already exists. When upserting data, you specify a field to use in determining whether or not the record is there. If there is a match on that field, then an update is performed, otherwise a new record is created. Performing an upsert with the REST API is easy – just use the HTTP PATCH method to send data to a URL specifying the object type, identity field and its value, for example, https://na1.salesforce.com/services/data/v20.0/sobjects/Account/myField__c/123456. The HTTP response’s status code tells you if a new record was inserted (201) or an existing record updated (204).
The Force.com REST API is just one of a whole smorgasbord of goodies planned for the Spring ’11 release. Register for the release preview webinar to learn more, and, if you’re keen to get started straight away, sign up for pre-release access right now!