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>Anatomy of a WebStack Application</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>Anatomy of a WebStack Application</h1> 13 14 <p>The simplest way to think of a Web application is as just some code which 15 gets run every time an HTTP request arrives at a specific network address and 16 which produces an HTTP response. Without WebStack, such code often needs to 17 be tailored to the software which causes it to be run, but with WebStack you 18 just need to do this:</p> 19 <ol> 20 <li>Write some application code which uses the WebStack API - this code can 21 be run within any of the supported environments.</li> 22 <li>Write some simple adapter or "glue" code - this code makes the 23 application work with each of the environments that you want to use and 24 should be much smaller in size than the application code.</li> 25 </ol> 26 27 <p>Most of the time, you need only to think about the first activity (writing 28 against the WebStack API).<br /> 29 </p> 30 31 <h2>A Very Simple Example</h2> 32 In the simplest case, you just need to produce a Python class which takes 33 this form: 34 <pre>class MyResource:<br /><br /> "This is a resource - something which defines the behaviour of an application."<br /><br /> def respond(self, trans):<br /> [Examine the transaction, decide what the user wants to do.]<br /> [Perform some kind of action with the information supplied.]<br /> [Produce some kind of response which tells the user what happened.]</pre> 35 36 <p>The parts of the pseudo-code in the above text which aren't valid Python 37 (ie. the bits in square brackets) will use various WebStack API calls to look 38 at what the user specified in the request and to send information back to the 39 user in the response.<br /> 40 </p> 41 42 <p>WebStack applications consist of resource classes which contain the 43 application code. In the above example, the only thing we need to consider is 44 what our code does, not how resource objects are created and invoked (that is 45 done in the adapter code). In more complicated applications, there may be a 46 need to create our own resource objects explicitly, but this is not 47 particularly interesting to think about at this point - see <a 48 href="paths-filesystem.html">"Treating the Path Like a Filesystem"</a> for a 49 discussion of multiple resource objects.<br /> 50 </p> 51 52 <h2>Design Considerations</h2> 53 54 <p>When writing an application, we must consider a number of factors which 55 have an impact on the code (and other things) that we will need to provide as 56 part of the finished product or service.</p> 57 <ul> 58 <li><a href="paths.html">URLs and Paths</a></li> 59 <li><a href="methods.html">Request Methods</a></li> 60 <li><a href="parameters.html">Request Parameters and Uploads</a></li> 61 <li><a href="responses.html">Responses and Presentation</a></li> 62 <li><a href="state.html">Cookies, Sessions and Persistent 63 Information</a></li> 64 </ul> 65 </body> 66 </html>