REST like interface

Curtis Maloney cmaloney at cardgate.net
Tue Oct 9 18:48:51 PDT 2007


Andreas Sliwka wrote:
> Greetings,
>   while writing a small application I decided that I'd like to have REST 
> like set of interfaces published through dbus.

I'm assuming you mean you want to map your DBus objects to a REST interface on a 
web site?  Essentially giving a HTTP RPC front end.

If so, I have done something close to this (using Django, a Python web 
framework) and JSON for the data encoding.

>   Consider an application that manages 3 kind of objects, each instance 
> having a unique ID and a set of attributes and and some methods. I'd 
> like to expose each of these instances through an interface, while 
> having a single main interface that has holds some functionality for the 
> service itself.
>  
>   Now my question: Is publishing such a REST interface feasible with dbus?

Absolutely.  It should be obvious how dbus paths can map to URLs.  The trick 
comes down to how do you specify the interface/method you wish to invoke.

A simple approach used by a friend was to make the last two path elements the 
interface and method.  You might also want to put the bus address or common name 
before the path...

So, you'd wind up with a request like:
----START---
POST /webservice/my.app.service/my/application/TypeA/id1/DoSomething/
Content-type: application/json
Content-length: XXX

["string1","string2"]
-----END----

In my case, we were using a very dumbed down CRUD scheme, which we're going to 
overhaul in version 2.  We rushed it somewhat, and really didn't stick to the 
semantics of HTTP.

We also used name parameters, not positional.  So the body of posts are send as 
dicts.  For returning errors, our responses are also dicts including the object 
type, success status, and either an object or error element.

>    I'd expect about a dozen instances of each type, so a total of less 
> than 40 interfaces would be created, is this too much?

As Havoc pointed out, you seem to have some terminology confusion here.  In my 
case, one of our object types has over 140,000 instances but only 2 interfaces.

(Many thanks to Simon, fallback objects have made this memory efficient :)

>   Furthermore, I'd really appreciate some help on how to code this in 
> python ...

As I mentioned... I did all of this in Python, and would be glad to help (and 
not just because it helps me, too :)

-- 
Curtis Maloney
cmaloney at cardgate.net



More information about the dbus mailing list