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