1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html"> 5 <title>URLs and Paths</title> 6 <meta name="generator" content="amaya 8.1a, see http://www.w3.org/Amaya/"> 7 <link href="styles.css" rel="stylesheet" type="text/css"> 8 </head> 9 10 <body> 11 <h1>URLs and Paths</h1> 12 13 <p>The URL at which your application shall appear is arguably the first part 14 of the application's user interface that any user will see. In this context, 15 a user can be any of the following things:</p> 16 <ul> 17 <li>A real person entering the URL into a browser's address bar.</li> 18 <li>A real person linking to your application by writing the URL in a 19 separate Web page.</li> 20 <li>A program which has the URL defined within it and which may manipulate 21 the URL to perform certain kinds of operations.</li> 22 </ul> 23 24 <h2>Interpreting Path Information</h2> 25 26 <p>What the URL is supposed to do is to say where (on the Internet or on an 27 intranet) your application resides and which resource or service is being 28 accessed, and these look like this:</p> 29 <pre>http://www.boddie.org.uk/python/WebStack.html</pre> 30 31 <p>With WebStack, we also talk about a "path" as being just the part of the 32 URL which refers to the resource or service, ignoring the actual Internet 33 address, and so these look like this:</p> 34 <pre>/python/WebStack.html</pre> 35 36 <p>When writing a Web application, most of the time you just need to 37 concentrate on the path because the address doesn't usually tell you anything 38 you don't already know. What you need to do is to interpret the path 39 specified in the request in order to work out which resource or service the 40 request is destined for.<br> 41 </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 - see <a href="parameters.html">"Request Parameters and 52 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 <h2>Paths To and Within an Application</h2> 60 One thing to be aware of in the code of an application is which part of a 61 path refers to the location of the application in a server environment and 62 which refers to some resource within the application itself. Consider this 63 path:<br> 64 65 <pre>/folder/application/resource</pre> 66 Let us say that the application was deployed in a Zope server instance inside 67 <code>folder</code> and with the name <code>application</code>. We may then 68 say that the path to the application is this: 69 <pre>/folder/application</pre> 70 Meanwhile, the path within the application is just this: 71 <pre>/resource</pre> 72 73 <div class="WebStack"> 74 <h3>WebStack API - Paths To Resources Within Applications</h3> 75 76 <p>On transaction objects, the following methods exist to inspect paths to 77 resources within applications.</p> 78 <dl> 79 <dt><code>get_path_info</code></dt> 80 <dd>This gets the path of a resource within an application.</dd> 81 <dt><code>get_virtual_path_info</code></dt> 82 <dd>This gets the path of a resource within a part of an application - 83 the application itself decides the scope of the path and can set the 84 "virtual path info" using the <code>set_virtual_path_info</code> 85 method.</dd> 86 </dl> 87 </div> 88 89 <h2>Approaches to Path Interpretation<br> 90 </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 </body> 120 </html>