GNOME web services integration: Introducing librest

When OpenedHand was first acquired by Intel I was asked to look into ways of making it easier to access web services from within GLIBish (i.e. Clutter & GTK) applications. We figured that as web services more important to the users of Moblin, and thus by extension, GNOME we needed some way to help developers access them.

So, I did some research, read up on RESTful. And thought yay, lots of services are claiming to be RESTful, let’s see if we can come up with some kind of service description language that we can autogenerate code from (ala, dbus-glib). Turns out that very few services actually adhere to this RESTful definition and my attempts to produce some kind of description language resulted in more lines of XML than code, hmmm.

Anyway, I persevered and looked at building an API that I would fine easy to drive RESTful web services with. After a few iterations I decided upon designing something with a somewhat Cairo-esque API.





Marco thinking RESTful thoughts.

The API is comprised of two parts, the first half is for making the requests (and is based on libsoup.) Here is an example:

  proxy = rest_proxy_new ("http://www.flickr.com/services/rest/", FALSE);
  call = rest_proxy_new_call (proxy);
  rest_proxy_call_add_params (call,
                              "method", "flickr.test.echo",
                              "api_key", "",
                              "format", "xml",
                              NULL);
  rest_proxy_call_run (call, NULL, NULL); /* obviously can do async instead */
  payload = rest_proxy_call_get_payload (call);
  len = rest_proxy_call_get_payload_length (call);

Easy, huh? Anyway, enough rambling for today’s blog post, next week i’ll talk about the really interesting stuff we’re (Ross and I) are working on to make parsing XML fun (yes, really, honestly, fun.)

Oh and and the source code can be found in git and it’s licensed under LGPLv2.1, etc etc. (Yes, we have too many libraries, when mature perhaps we can move this into libsoup.)

9 thoughts on “GNOME web services integration: Introducing librest

  1. Zeeshan Ali

    Neat stuff!

    Regarding the xml parsing made simple, that is also another neat great idea but tell me the idea didn’t spark from my latest mail to gupnp ml. 😉

    Reply
  2. Ross Burton

    Considering that your post is about schema-specific XML generation and Rob is talking about generic XML parsing, and we’ve had working code in the repository for a few months, it’s fairly likely that it wasn’t sparked by your GUPnP post. 🙂

    Reply
  3. Some Dude

    Can you describe what makes the API you’ve defined restful?

    To me, it looks like you have a ‘proxy’ (for the ‘remote object’?), and you’re calling a ‘method’ on it. What you’re saying is, this is just another RPC, right?

    But is REST, the methods are GET, POST, PUT and so on, and what you’re calling a method is actually a resource. (There are no objects).

    What about caching? What about timeouts? What about link following to discover new resources?

    Reply
  4. Tommi Komulainen

    I don’t believe XML parsing, or parsing anything for that matter, is ever going to be what you might call fun. (Theory meets real world comes to mind.) I’m happy to let someone else handle parsing and hand out a nice object containing the stuff and let me just deal with the content.

    Reply
  5. rjw

    I echo Some Dudes concerns….
    Please, please, read Restful Web Services by Sam Ruby.
    A good REST client library would be a great thing for C.
    If you want a service description language, please take a look at WADL.

    The best way to support what you are trying to do with url construction would be url templates, yeah its yet another embedded string language, but you use regexes, don’t you?

    Seriously, the last thing we need is a library claiming the name librest to be another POX-RPC nightmare. Please, please, please, learn about REST – the book I recommend is far better for this than the rambling thesis or any web resource I’ve found ( irony eh) – before widely publishing or using this api.

    One of the most important distinctions between REST and RPC is the primacy of representations, and it would be very sensible to provide default, vaguely useful implementations for some things: JSON, Atom documents, and a way to define certain parts of a representation as links ( and please don’t limit this to XML). Links are really the key to REST being something more than another jokey RPC system.

    Reply
  6. Pingback: mrego's status on Thursday, 21-May-09 17:56:40 UTC - Identi.ca

  7. Pingback: Rob Bradford: A little bit more RESTful | Full-Linux.com

  8. Pingback: A little bit more RESTful at Rob Bradford’s Weblog

Leave a Reply

Your email address will not be published. Required fields are marked *