[Twisted-web] Twisted and RESTful app

L. Daniel Burr ldanielburr at mac.com
Wed Aug 1 08:53:37 EDT 2007


Hi Vincent,

On Wed, 01 Aug 2007 07:42:03 -0500, Vincent Bernat <bernat at luffy.cx> wrote:

>
> Hi !
>
> I would like to add a RESTful interface to an existing Twisted
> application. To allow a human to interact easily with the
> application, I want to output bare minimal XHTML (1990 HTML
> without any presentation, just some class to allow to easily
> parse the result).
>
> I have looked at twisted.web framework. One good point is that
> there are different methods for each action (GET, HEAD, POST,
> PUT, DELETE). However, there is nothing to generate XHTML easily.
>
> I have looked at Nevow which contains two interesting ways to
> generate XHTML code (Stan and templates). But the only method to
> render is renderHTTP. I suppose that the HTTP action is somewhere
> in the context, but I did not find where yet.
>

To obtain the request, do this:

request = inevow.IRequest(ctx)

Then, just dispatch based on request.method

> I could mix twisted.web with Stan or with Nevow templates. I
> could also just use twisted.web and use ElementTree to generate
> simple XHTML page. But do some of you have some suggestions about
> implementing a RESTful service using Twisted ?
>

It really depends upon your personal tastes in this case.  You
could use plain twisted.web, with some templating library; you
could use twisted.web2 with some templating library; you could
use nevow.  All will work just fine in a REST-style design, as
they all support the same basic IResource interface, more or
less.

Hope this helps,

Daniel



More information about the Twisted-web mailing list