Saturday, February 21, 2009

Restish on App Engine

I've been experimenting with the Restish web framework lately. Overall the code is very minimal and stays out of your way, and I have been quite impressed with it so far. The docs are alright for such a new project, and the guys working on it have been pretty responsive to bugs and suggestions.

The next step in my experiment is to get Restish working with Google App Engine. It turns out to be quite simple. The basic hello world app looks like the following:


#!/usr/bin/env python

import wsgiref.handlers
from restish import app, http, resource

class Root(resource.Resource):
@resource.GET()
def index(self, request):
return http.ok([], 'Hello World!')

def main():
application = app.RestishApp(Root())
wsgiref.handlers.CGIHandler().run(application)

if __name__ == '__main__':
main()


You will also have to include the Restish source tree in your project (or use the zip importer to import it from a zip file). This example is about the simplest way possible to do it, and I bet it wouldn't be difficult to get a paste created project working on App Engine.

So far, so good. I'll report later if I run into any issues.

4 comments:

Meesh said...

You're such a dork. ;)

Matt Goodall said...

Actually, it can be simpler - the Root resource can just be a function:

def root(request):
return http.ok([], 'Hello World!')

Yeah I know, a function is not terribly useful as a root resource but it comes in very handy for writing simple leaf resources so I thought it was worth mentioning ;-).

Matt Goodall said...

Also ... thanks for posting this example. It's great to see that restish runs just fine on GAE :).

Chuck said...

Hey Matt, thanks for Restish! :)

I've only tested the very basics thus far, but hopefully I will be able to flex more of its muscles soon.