REST API, ProgrammableWeb and cURL

I’ve just seen a great ProgrammableWeb post about our forthcoming REST API and webinar.

Jeremy Glassenberg makes an excellent point about the ease of development in REST, and how that’s resulted in immense growth of REST APIs.

We, as developers, should be thinking about the same thing.  What happens when you have a REST API for the application you’ve built on  What new opportunities does that create?  For one thing, other people will be able to more easily access *your* data and functionality – they’ll be able to more easily mash up your app with some other app (ProgrammableWeb has a great directory of APIs).

And yes, it’s really easy to use.  Once you have an authorisation token (you can use OAuth 2.0 to generate one), using the REST API (Quinton gave a sneak peek in a post a while back) is a doddle.  You can even use the venerable cURL command line tool.

For example, you could retrieve the name field from your FooBar object using something like this:

curl -H "Authorization: OAuth token" -H "X-PrettyPrint:1"

What you’d get streaming out on your console window is some nice JSON.  Perhaps something like this:

"done" : true, "totalSize" : 33, "records" :
{  "attributes" : {
"type" : "FooBar", "url" : "/services/data/v2x.x/sobjects/FooBar/001E000000IRFmaIAH"}, {
"Name" : "Test 1"
}  ,
{  "attributes" : {
"type" : "FooBar", "url" : "/services/data/v2x.x/sobjects/FooBar/001E000000IomazIAB"
"Name" : "Test 2"

You’d also have access to the metadata using the REST API – data about the shape of your data.  All from the command line, if you really want it – or any tool or language that handles basic HTTP.

REST API is not GA yet – it’s a pilot feature – but we’ll soon be running a developer preview. Signup to learn more – and in the mean time think about what this means to your apps as well!

tagged Bookmark the permalink. Trackbacks are closed, but you can post a comment.
  • tec-goblin

    I have some issues with your REST API. I know it’s quite early, and that’s why I think my feedback would be useful.
    1st: I haven’t really understood how authorization works. If I want to integrate a Salesforce call in an external webpage, how do I access an authorization token?
    Is there a way to handle authorization delegation (like windows authentification, using another login etc)?
    2nd: It’s ok to try to copy Microsoft by doing a REST API, but wouldn’t it be important to improve first the SOAP API right now? The current soap API for example isn’t really object oriented. I cannot easily do an object-relational mapping, perform LINQ queries, send a command to “create a contract” which would also create the product descendants etc. In short, it is useful only for querying and batch processing, but if I want for example to handle in a transactional way the creation of a contract (and cancel everything if one of its products has a problem) I cannot do it easily.
    Naming conventions are a complete mess, particularly for custom objects and fields (I can elaborate on that).
    3rd: Could you elaborate more on the CRUD operations? Can we use PUT for Insert and POST for updates, as it is traditionally in REST? Can we do it for multiple records?
    4th: I love the way most RESTful frameworks use clear URLs for handy scenarii. Like /Contracts/4 to get the contract with the id 4, or Contracts/4/name to get only its name. Will you support this kind of URL mapping? Or even /Contracts/name=5 (if we want to query by another field).
    I suppose it’s quite verbose, as the id in salesforce is unique for all objects, so it would be something like /Contracts/00xdh429894990999f
    (by the way, do you have plans to abolish this quirk? Apart from making the URLs very user-hostile, it’s horrible when I want to load in the sandbox two tables with foreign keys and I cannot keep the ids I want because Salesforce forces them to another id).
    Do you have plans to use Microsoft’s OData format? It’s open right now, standardized and used for different purposes. No need to reinvent the wheel, I suppose.

  • Nikhil

    Can you please explain the Use of REST Api with a simple example and how it is better then Soap API.
    That would be a great help

  • @Nikhil – Check out this article which I think provides many great examples:
    @tec-goblin – Check out the article too – it answers some of your questions about authorization (OAuth 2.0), as well as the CRUD operations and URL mappings.
    For other questions, which I cannot answer, please try the new REST discussion board: