[Zope] How to get REST friendly urls from sql database

Paul Winkler pw_lists at slinkp.com
Wed Feb 21 10:27:22 EST 2007


On Wed, Feb 21, 2007 at 12:32:30PM +0100, Gaute Amundsen wrote:
> On Tuesday 20 February 2007 17:39, Paul Winkler wrote:
> <snip>
> > Another option is that the object at /articles could be an instance
> > of a class that looks something like:
> >
> > class MyArticleContainer():
> >
> >     def __before_publishing_traverse__(self, unused, request):
> >         # Save the rest of the path as 'traverse_subpath'.
> >         request.set('traverse_subpath',
> >                     reversed(request['TraversalRequestNameStack']))
> >         # Tell the publisher to stop traversing now.
> >         request['TraversalRequestNameStack'][:] = []
> >
> >     def __call__(self, *args, **kw):
> >         subpath = self.REQUEST['traverse_subpath']
> >         data = get_data_however_you_like(subpath)
> >         return data
> >
> >
> > For background, read the stuff about traversal hooks at
> > http://wiki.zope.org/zope2/ZPublisher
> 
> 
> Hm.. that looks more like what I had in mind when I posted, but allso quite a 
> bit more overhead than rewriterules.
> At least for me that has never written a product.

Well, it may feel like a lot of work to you the first time :-)

> I will have to think about that one..
> Would you care to elaborate a little bit on what the tradeoffs would be?

My approach might be good if:

- the logic for looking up articles is more complex than can be
comfortably expressed using apache rewrite rules, and/or

- the logic for looking up articles requires state that's internal to zope.


You could instead follow Andreas' suggestion and use a through-the-web
Script.  It might look something like:

article_id = traverse_subpath[-1]
data =  context.get_the_data_somehow(article_id)
return data

Your URLs would then look like:

http://example.com/folder_id/script_id/article_id

Note that naming the script index_html doesn't really help, because
http://example.com/folder_id/article_id wouldn't invoke the script.

--

Paul Winkler
http://www.slinkp.com


More information about the Zope mailing list