Nested Routes

dscape edited this page Mar 19, 2011 · 8 revisions

Nested Routes

It’s common to have resources that are logically children of other resources. In rewrite we call them nested resources, e.g.

    <resource name=":user"> 
      <resource name=":album"> 
        <member action=":picture"/> 
Method Path Meaning Mapping
PUT /dscape Update user dscape /resource/user.xqy?action=put&user=dscape
GET /dscape/thailand See Thailand Album /resource/album.xqy?action=get&user=dscape&album=thailand
GET /dscape/thailand/burger.jpg See the burger picture taken in thailand by user dscape /resource/album.xqy?action=picture&user=dscape&album=thailand&picture=burger.jpg

As you can see nested routes can also be dynamic, allowing behaviors like multiple users having multiple pages using a syntax like /dscape/aboutme instead of /user/dscape/page/aboutme.

Determining the action is an important step in rewrite because it tells the application what method to invoke in runtime when you do a specific request. Because it is possible to have actions with / in rewrite we decided the following rules regarding actions:

  • Remove : and * from the beginning of the action. No-one wants to call the :user function or *database xquery script so these should be removed.
  • For actions that have / we replace / with - thus making it valid function and file names.