REST support in Grok

Registered by Steve Schmechel on 2009-06-16

Doc review project

Blueprint information

Status:
Started
Approver:
Grok Doc
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
Wilson
Definition:
Approved
Series goal:
Proposed for 1.0
Implementation:
Good progress
Milestone target:
None
Started by
Wilson on 2009-09-24

Related branches

Sprints

Whiteboard

P. Wilson : Began review process.

 * Can see error already with old style REST suppot via

 class AtomPubProtocol(grok.RESTProtocol):
    grok.layer(AtomPubLayer)
    grok.name('atompub') # a nicer name

whereas the Grok changelog states that:

"Similar to the layers and skins restructuring, the grok.RESTProtocol baseclass has been removed in favour of a grok.restskin(name) directive that can be used on REST layer interfaces. Introduced the IRESTLayer base interfaces for defining REST layers."

Fixing the example requires removing the above class and adding:

grok.restskin('rest')

to the AtomPubLayer defined.

Additional Thoughts
==============

* A more realistic example where headers are correctly set might be useful.

* Would be useful to show the doctest update required to test this rest interface, e.g.:

~~~~~~~~~~~~%<~~~~~~~~~~~~~
Do a functional doctest test on the app.
========================================

:Test-Layer: functional

Let's first create an instance of Grok_doc_tests at the top level:

   >>> from grok_doc_tests.app import Grok_doc_tests, MyContainer
   >>> root = getRootFolder()
   >>> root['app'] = Grok_doc_tests()
   >>> root['app']['container'] = MyContainer()

Run tests in the testbrowser
----------------------------

The zope.testbrowser.browser module exposes a Browser class that
simulates a web browser similar to Mozilla Firefox or IE. We use that
to test how our application behaves in a browser. For more
information, see http://pypi.python.org/pypi/zope.testbrowser.

Create a browser and visit the instance you just created:

   >>> from zope.testbrowser.testing import Browser
   >>> browser = Browser()
   >>> browser.open('http://localhost/++rest++rest/app/container')

Check some basic information about the page you visit:

   >>> browser.url
   'http://localhost/++rest++rest/app/container'
   >>> browser.headers.get('Status').upper()
   '200 OK'
~~~~~~~~~~~~%<~~~~~~~~~~~~~

* Can see possibility for expansion to cover applying default skins to remove ++rest++:

@grok.subscribe( ... , grok.IBeforeTraverseEvent)
def restSkin(obj, event):
   if not RestAPILayer.providedBy(event.request):
      grok.util.applySkin(event.request, RestAPILayer, grok.IRestSkinType)

14th October 2009 - JW-Kolman requests expansion to detail how applying skins automatically affects requests to all subobjects of the traversed skinned object.

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.