1 <?xml version="1.0" encoding="iso-8859-1"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 <html xmlns="http://www.w3.org/1999/xhtml"> 5 <head> 6 <title>URLs and Paths</title> 7 <meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/" /> 8 <link href="styles.css" rel="stylesheet" type="text/css" /> 9 </head> 10 11 <body> 12 <h1>URLs and Paths</h1> 13 14 <p>The URL at which your application shall appear is arguably the first part 15 of the application's user interface that any user will see. In this context, 16 a user can be any of the following things:</p> 17 <ul> 18 <li>A real person entering the URL into a browser's address bar.</li> 19 <li>A real person linking to your application by writing the URL in a 20 separate Web page.</li> 21 <li>A program which has the URL defined within it and which may manipulate 22 the URL to perform certain kinds of operations.</li> 23 </ul> 24 25 <h2>Interpreting Path Information</h2> 26 27 <p>What the URL is supposed to do is to say where (on the Internet or on an 28 intranet) your application resides and which resource or service is being 29 accessed, and these look like this:</p> 30 <pre>http://www.boddie.org.uk/python/WebStack.html</pre> 31 32 <p>With WebStack, we also talk about a "path" as being just the part of the 33 URL which refers to the resource or service, ignoring the actual Internet 34 address, and so these look like this:</p> 35 <pre>/python/WebStack.html</pre> 36 37 <p>When writing a Web application, most of the time you just need to 38 concentrate on the path because the address doesn't usually tell you anything 39 you don't already know. What you need to do is to interpret the path 40 specified in the request in order to work out which resource or service the 41 request is destined for.<br /> 42 </p> 43 44 <div class="WebStack"> 45 <h3>WebStack API - Path Methods in Transaction Objects</h3> 46 47 <p>WebStack provides the following transaction methods for inspecting path 48 information:</p> 49 <dl> 50 <dt><code>get_path</code></dt> 51 <dd>This gets the entire path of a resource including parameter 52 information - see <a href="parameters.html">"Request Parameters and 53 Uploads"</a>.</dd> 54 <dt><code>get_path_without_query</code></dt> 55 <dd>This gets the entire path of a resource but without any parameter 56 information.</dd> 57 </dl> 58 </div> 59 60 <h2>Paths To and Within an Application</h2> 61 One thing to be aware of in the code of an application is which part of a 62 path refers to the location of the application in a server environment and 63 which refers to some resource within the application itself. Consider this 64 path:<br /> 65 66 <pre>/folder/application/resource</pre> 67 Let us say that the application was deployed in a Zope server instance inside 68 <code>folder</code> and with the name <code>application</code>. We may then 69 say that the path to the application is this: 70 <pre>/folder/application</pre> 71 Meanwhile, the path within the application is just this: 72 <pre>/resource</pre> 73 74 <div class="WebStack"> 75 <h3>WebStack API - Paths To Resources Within Applications</h3> 76 77 <p>On transaction objects, the following methods exist to inspect paths to 78 resources within applications.</p> 79 <dl> 80 <dt><code>get_path_info</code></dt> 81 <dd>This gets the path of a resource within an application.</dd> 82 <dt><code>get_virtual_path_info</code></dt> 83 <dd>This gets the path of a resource within a part of an application - 84 the application itself decides the scope of the path and can set the 85 "virtual path info" using the <code>set_virtual_path_info</code> 86 method.</dd> 87 </dl> 88 </div> 89 90 <h2>Approaches to Path Interpretation</h2> 91 92 <p>There are various differing approaches to the problem of interpreting 93 paths to resources within Web applications, but these can mostly be divided 94 into three categories:</p> 95 96 <table border="1" cellspacing="0" cellpadding="5"> 97 <tbody> 98 <tr> 99 <th>Approach</th> 100 <th>Examples</th> 101 </tr> 102 <tr> 103 <td><a href="paths-filesystem.html">Path as filesystem</a></td> 104 <td>WebDAV interface to a repository</td> 105 </tr> 106 <tr> 107 <td><a href="paths-services.html">Path as resource or service 108 identifier</a></td> 109 <td>A Web shop with very simple paths, eg. <code>/products</code>, 110 <code>/checkout</code>, <code>/orders</code></td> 111 </tr> 112 <tr> 113 <td><a href="paths-opaque.html">Path as opaque reference</a></td> 114 <td>An e-mail reader where the messages already have strange and 115 unreadable message identifiers</td> 116 </tr> 117 </tbody> 118 </table> 119 120 <h2>Path Info Support in Server Environments</h2> 121 122 <p>The following table summarises the support for paths within applications 123 amongst the supported server environments or frameworks within WebStack:</p> 124 125 <table border="1" cellspacing="0" cellpadding="5"> 126 <tbody> 127 <tr> 128 <th>Framework</th> 129 <th>Behaviour/Level of Support</th> 130 </tr> 131 <tr> 132 <td>BaseHTTPRequestHandler</td> 133 <td>Same as path (correct)</td> 134 </tr> 135 <tr> 136 <td>CGI</td> 137 <td>Path beyond resource (correct)</td> 138 </tr> 139 <tr> 140 <td>Java Servlet API</td> 141 <td>Path beyond context (correct)</td> 142 </tr> 143 <tr> 144 <td>mod_python</td> 145 <td>Path beyond resource (correct)</td> 146 </tr> 147 <tr> 148 <td>Twisted</td> 149 <td>Same as path (correct)</td> 150 </tr> 151 <tr> 152 <td>Webware</td> 153 <td><= 0.8.1: Not supported (needs <code>ExtraPathInfo</code> 154 support)<br /> 155 > 0.8.1: Path beyond context (correct)</td> 156 </tr> 157 <tr> 158 <td>WSGI</td> 159 <td>Path beyond resource (correct)</td> 160 </tr> 161 <tr> 162 <td>Zope</td> 163 <td>Path beyond resource (correct)</td> 164 </tr> 165 </tbody> 166 </table> 167 </body> 168 </html>