[Grok-dev] Re: Is there an easy way to customize URL used for
grok.REST (use suffix instead of prefix) ?
cstrong at arielpartners.com
Sun Jun 8 18:31:06 EDT 2008
We finally got a chance to try this out, and thanks to your excellent
advice, it is working perfectly.
>> I admit I have not yet grasped the full zen of IRESTLayer, REST,
>> RESTProtocol, etc.
> Yeah, it's a bit involved. It's similar to skins.
> A skin is a particular layer that is published. It has a name
> ++skin++foo. Views are associated with layers. Layers can extend other
> layers and thus you can compose bigger layers out of smaller ones if
> you want.
> A rest protocol is a particular rest layer that's published. It has a
> name ++rest++foo. REST views are associated with rest layers.
We ended up creating an adapter that knows how to retrieve XML from any
object that has an xml() method.
We put the boilerplate code in a separate "traversers.py" module:
from zope.publisher.http import applySkin
def traverse(self, name):
if name == 'xml':
if not MyLayer.providedBy(self.request):
applySkin(self.request, MyLayer, grok.IRESTSkinType)
def __init__(self, context):
self.context = context
Then each class in the application that needs to have a REST interface
simply needs to do this:
>> Yes, something like that which also incorporates my other use case
>> described above would be fantastic!
>> I am way too much of a newbie to contribute code, but can contribute
>> the writing and executing of tests and documentation.
> I suggest you get some experience getting this pattern going with
> REST, and then start a new thread based on your experiences. It looks
> like we want something that's like a model and a view at the same
> time. This can be accomplished with views on views too, by the way.
> Perhaps that is the cleaner solution; but I'm not sure.
The above code is not bad, but I am still intrigued by your idea of
adding something like RelativeRestView
Thanks so much for your help!
> Grok-dev mailing list
> Grok-dev at zope.org
More information about the Grok-dev