1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type" /> 5 <title>A Very Simple Example</title> 6 <meta name="generator" 7 content="amaya 8.1a, see http://www.w3.org/Amaya/" /> 8 <link href="styles.css" rel="stylesheet" type="text/css" /> 9 </head> 10 <body> 11 <h1>A Very Simple Example</h1> 12 At its simplest a WebStack application is just a Python class, 13 living in a module or package, having this form: 14 <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> 15 <p>The parts of the pseudo-code in 16 the above text which aren't valid Python 17 (ie. the bits in square brackets) will use various WebStack API calls 18 to look 19 at what the user specified in the request and to send information back 20 to the 21 user in the response.</p> 22 <h2>Resource Classes 23 </h2> 24 <p>It is in this kind of resource class that we write the 25 application code. In the above example, the only thing we need to 26 consider is 27 what our code does, not how resource objects are created and invoked 28 (that is 29 done in the <a href="deploying.html">adapter code</a>). In more 30 complicated applications, there may 31 be a 32 need to create our own resource objects explicitly, but this is not 33 particularly interesting to think about at this point - see <a 34 href="paths-filesystem.html">"Treating the Path Like 35 a Filesystem"</a> for a 36 discussion of multiple resource objects. 37 </p> 38 <h2>Design Considerations</h2> 39 <p>When writing an application, we 40 must consider a number of factors which 41 have an impact on the code (and other things) that we will need to 42 provide as 43 part of the finished product or service.</p> 44 <ul> 45 <li><a href="paths.html">URLs and Paths</a></li> 46 <li><a href="methods.html">Request Methods</a></li> 47 <li><a href="parameters.html">Request Parameters and Uploads</a></li> 48 <li><a href="responses.html">Responses and Presentation</a></li> 49 <li><a href="state.html">Cookies, Sessions and Persistent 50 Information</a></li> 51 </ul> 52 </body> 53 </html>