provide a simple way to write REST APIs in Zope 2.


REST component provides mainly a base class REST which behave a lot like a Grok view:

from import REST

class MyAction(REST):
    """My action REST API.

    def POST(self, name, value):
        # Called by POST /content/++rest++myaction&name=foo?value=bar
        return 'Success'

    def GET(self):
        # Called by GET /content/++rest++myaction
        values = self.context.something()
        return self.json_response(values)

You just have to grok your package to make it available.

  • You can provide: POST, GET, HEAD, DELETE requests.
  • You can use the directives, grok.require and grok.context to configure your REST API. They work exactly like on a grok.View.
  • If you need, you can manually query a REST component with the help of

Nesting REST component

You can nest REST component. In that you should use the grok directive adapts in order to define which is the parent handler, and the context:

from import REST
from five import grok
from OFS.Folder import Folder

class ParentHandler(REST):

    def GET(self):
        # Called by GET /folder/++rest++parenthandler
        return u'Hello'

class ChildHandler(REST):
    grok.adapts(ParentHandler, Folder)

    def GET(self):
        # Called by GET /folder/++rest++parenthandler/childhandler
        return u'Child

RESTWithTemplate component

You can alternatively use the base class RESTWithTemplate. The only difference is that your class will be associated to a Grok template automatically.


Sources can be found in Mercurial at:

Available releases

Release version Release date Release files 1.3 May 23, 2013 11:15:21 AM 1.2 Sep 4, 2012 11:08:03 AM 1.1 Nov 7, 2011 1:35:42 PM 1.0.1 Oct 7, 2010 3:22:16 PM 1.0 Jul 15, 2010 6:30:10 PM

License: New BSD