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