Treating the Path Like a Filesystem

...or as a reference into deeply categorized resources. In this approach, we take a path like this...

/documents/news/2005/article.html

...and we consider documents, news, and 2005 as directories, and article.html as a file-like resource. If we ask for the following path...

/documents/news/2005

...we may decide to provide a listing of files within that directory, or we may decide to refuse such a request. Indeed some approaches will insist that such a listing may only be produced with the following path instead:

/documents/news/2005/

Applications of this kind are quite common since the publishing of files on a Web server often just involves exposing parts of a real filesystem to requests through the server.

Resource Hierarchies in WebStack

We might decide to represent components in these kinds of paths using different resource classes, so that folders or directories are represented by one kind of resource class and files or documents are represented by other kinds of resource classes. We might then predefine a hierarchy of resources so that when a request arrives for a resource, we can check it against the hierarchy and process the request according to whichever type of resource is being accessed.

Consider the above hierarchy; we would implement such a hierarchy with a resource object mapped to documents, and that resource object would contain a mapping of years to other resources. Eventually, at the bottom of the hierarchy, individual resources would represent articles and be mapped to names such as article.html.

WebStack API - Predefining Resource Hierarchies in Adapter Code

WebStack provides a resource class for convenient mapping of path components (ie. names) to resource objects: WebStack.Resources.ResourceMap.MapResource

This class can be used in adapter or "glue" code to initialise an application as follows:

from WebStack.Resources.ResourceMap import MapResource
article_resource = [some resource representing the article]
year_2004_resource = [a MapResource with definitions]
year_2005_resource = MapResource({"article.html" : article_resource})
news_resource = MapResource({"2005" : year_2005_resource, "2004" : year_2004_resource})
documents_resource = MapResource({"news" : news_resource})
top_resource = MapResource({"documents" : documents_resource})

Of course, predefining hierarchies is not the only way to support such hierarchies. We could inspect paths and act dynamically on the supplied information.