ResourceMap - Simple Mappings from Names to Resources

The ResourceMap module provides classes (although currently only one class is supplied) which act as standard WebStack resources, but which examine the path or URL from incoming requests and direct such requests to other resources based on the contents of the path or URL. In other words, such classes map names or patterns to WebStack resources and dispatch requests accordingly.

Introducing MapResource

The "Treating the Path Like a Filesystem" document contains an example involving the MapResource class; this class is initialised with a dictionary mapping names to resources as described below.

WebStack API - The MapResource Class

The MapResource class (found in the WebStack.Resources.ResourceMap module) maps names to resource objects, where to select a resource the corresponding name must match the first component discovered in the virtual "path info". For example, consider the following virtual "path info" (where there may have been more information in the path, but this has already been processed):

/documents/news/2005/article.html

Here, the name documents would match the above virtual "path info". Meanwhile, after processing more of the information, we might have the following remains of the path:

/2005/article.html

Here, the name 2005 would match, leaving the following information unprocessed:

/article.html

Here, the name article.html would match. However, let us consider the following original virtual "path info" instead:

/documents/news/2005/

After processing the leading components, we may instead end up with this:

/

Here, only an empty string as the name will specifically match the above.

Further Reading

The API documentation for the MapResource class provides more detail on the subject of name matching, including the special "catch all" name and a discussion of the pass-through parameter.