1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>Anatomy of a WebStack Application</title> 5 <meta name="generator" 6 content="amaya 8.1a, see http://www.w3.org/Amaya/"> 7 <link xmlns:xlink="http://www.w3.org/1999/xlink" href="styles.css" 8 rel="stylesheet" type="text/css"> 9 </head> 10 <body> 11 <h1>Anatomy of a WebStack Application</h1> 12 <p>The simplest way to think of a Web application is as just some code 13 which 14 gets run every time an HTTP request arrives at a specific network 15 address and 16 which produces an HTTP response. Without WebStack, such code often 17 needs to 18 be tailored to the software which causes it to be run, but with 19 WebStack you 20 just need to do this:</p> 21 <ol> 22 <li>Write some application code which uses the WebStack API - this 23 code can be run within any of the supported environments.</li> 24 <li>Write some simple adapter or "glue" code - this code makes the 25 application work with each of the environments that you want to use and 26 should be much smaller in size than the application code.</li> 27 </ol> 28 <p>Most of the time, you need only to think about the first activity 29 (writing 30 against the WebStack API).<br> 31 </p> 32 <h2>A Very Simple Example</h2> 33 In the simplest case, you just need to produce a Python class which 34 takes 35 this form: 36 <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> 37 <p>The parts of the pseudo-code in the above text which aren't valid 38 Python 39 (ie. the bits in square brackets) will use various WebStack API calls 40 to look 41 at what the user specified in the request and to send information back 42 to the 43 user in the response.<br> 44 </p> 45 <p>WebStack applications consist of resource classes which contain the 46 application code. In the above example, the only thing we need to 47 consider is what our code does, not how resource objects are created 48 and invoked (that is done in the adapter code). In more complicated 49 applications, there may be a need to create our own resource objects 50 explicitly, but this is not particularly interesting to think about at 51 this point - see <a href="paths-filesystem.html">"Treating the Path 52 Like a Filesystem"</a> for a discussion of multiple resource objects.<br> 53 </p> 54 <h2>Design Considerations</h2> 55 <p>When writing an application, we must consider a number of factors 56 which 57 have an impact on the code (and other things) that we will need to 58 provide as 59 part of the finished product or service.</p> 60 <ul> 61 <li><a href="paths.html">URLs and Paths</a></li> 62 <li><a href="methods.html">Request Methods</a></li> 63 <li><a href="parameters.html">Request Parameters and Uploads</a></li> 64 <li><a href="responses.html">Responses and Presentation</a></li> 65 </ul> 66 </body> 67 </html>