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.</p> 42 43 <div class="WebStack"> 44 <h3>WebStack API - Path Methods in Transaction Objects</h3> 45 46 <p>WebStack provides the following transaction methods for inspecting path 47 information:</p> 48 <dl> 49 <dt><code>get_path</code></dt> 50 <dd>This gets the entire path of a resource including parameter 51 information (as described in <a href="parameters.html">"Request 52 Parameters and Uploads"</a>).</dd> 53 <dt><code>get_path_without_query</code></dt> 54 <dd>This gets the entire path of a resource but without any parameter 55 information.</dd> 56 </dl> 57 </div> 58 59 <p>Sometimes, a "query string" will be provided as part of a URL; for 60 example:</p> 61 <pre>http://www.boddie.org.uk/application?param1=value1</pre> 62 63 <p>The question mark character marks the beginning of the query string which 64 contains encoded parameter information; such information and its inspection 65 is discussed in <a href="parameters.html">"Request Parameters and 66 Uploads"</a>.</p> 67 68 <h2>Paths To and Within an Application</h2> 69 One thing to be aware of in the code of an application is which part of a 70 path refers to the location of the application in a server environment and 71 which refers to some resource within the application itself. Consider this 72 path:<br /> 73 74 <pre>/folder/application/resource</pre> 75 Let us say that the application was deployed in a Zope server instance inside 76 <code>folder</code> and with the name <code>application</code>. We may then 77 say that the path to the application is this: 78 <pre>/folder/application</pre> 79 Meanwhile, the path within the application is just this: 80 <pre>/resource</pre> 81 82 <div class="WebStack"> 83 <h3>WebStack API - Paths To Resources Within Applications</h3> 84 85 <p>On transaction objects, the following methods exist to inspect paths to 86 resources within applications.</p> 87 <dl> 88 <dt><code>get_path_info</code></dt> 89 <dd>This gets the path of a resource within an application.</dd> 90 <dt><code>get_virtual_path_info</code></dt> 91 <dd>This gets the path of a resource within a part of an application - 92 the application itself decides the scope of the path and can set the 93 "virtual path info" using the <code>set_virtual_path_info</code> 94 method.</dd> 95 </dl> 96 </div> 97 98 <h2>Approaches to Path Interpretation</h2> 99 100 <p>There are various differing approaches to the problem of interpreting 101 paths to resources within Web applications, but these can mostly be divided 102 into three categories:</p> 103 104 <table border="1" cellspacing="0" cellpadding="5"> 105 <tbody> 106 <tr> 107 <th>Approach</th> 108 <th>Examples</th> 109 </tr> 110 <tr> 111 <td><a href="paths-filesystem.html">Path as filesystem</a></td> 112 <td>WebDAV interface to a repository</td> 113 </tr> 114 <tr> 115 <td><a href="paths-services.html">Path as resource or service 116 identifier</a></td> 117 <td>A Web shop with very simple paths, eg. <code>/products</code>, 118 <code>/checkout</code>, <code>/orders</code></td> 119 </tr> 120 <tr> 121 <td><a href="paths-opaque.html">Path as opaque reference</a></td> 122 <td>An e-mail reader where the messages already have strange and 123 unreadable message identifiers</td> 124 </tr> 125 </tbody> 126 </table> 127 128 <h2>Path Info Support in Server Environments</h2> 129 130 <p>The following table summarises the support for paths within applications 131 amongst the supported server environments or frameworks within WebStack:</p> 132 133 <table border="1" cellspacing="0" cellpadding="5"> 134 <tbody> 135 <tr> 136 <th>Framework</th> 137 <th>Behaviour/Level of Support</th> 138 </tr> 139 <tr> 140 <td>BaseHTTPRequestHandler</td> 141 <td>Same as path (correct)</td> 142 </tr> 143 <tr> 144 <td>CGI</td> 145 <td>Path beyond resource (correct)</td> 146 </tr> 147 <tr> 148 <td>Java Servlet API</td> 149 <td>Path beyond context (correct)</td> 150 </tr> 151 <tr> 152 <td>mod_python</td> 153 <td>Path beyond resource (correct)</td> 154 </tr> 155 <tr> 156 <td>Twisted</td> 157 <td>Same as path (correct)</td> 158 </tr> 159 <tr> 160 <td>Webware</td> 161 <td><= 0.8.1: Not supported (needs <code>ExtraPathInfo</code> 162 support)<br /> 163 > 0.8.1: Path beyond context (correct)</td> 164 </tr> 165 <tr> 166 <td>WSGI</td> 167 <td>Path beyond resource (correct)</td> 168 </tr> 169 <tr> 170 <td>Zope</td> 171 <td>Path beyond resource (correct)</td> 172 </tr> 173 </tbody> 174 </table> 175 </body> 176 </html>