PageRenderTime 18ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/docs/source/web/gettingstarted.rst

https://bitbucket.org/prologic/circuits/
ReStructuredText | 67 lines | 39 code | 28 blank | 0 comment | 0 complexity | a733837bed79bea8dc7b07e9774fc35d MD5 | raw file
 1.. _web_getting_started:
 2
 3Getting Started
 4===============
 5
 6Just like any application or system built with circuits, a circuits.web
 7application follows the standard Component based design and structure
 8whereby functionality is encapsulated in components. circuits.web
 9itself is designed and built in this fashion. For example a circuits.web
10Server's structure looks like this:
11
12.. image:: ../images/CircuitsWebServer.png
13
14To illustrate the basic steps, we will demonstrate developing
15your classical "Hello World!" applications in a web-based way
16with circuits.web
17
18To get started, we first import the necessary components:
19
20.. code-block:: python
21   
22   from circutis.web import Server, Controller
23   
24
25Next we define our first Controller with a single Request Handler
26defined as our index. We simply return "Hello World!" as the response
27for our Request Handler.
28
29.. code-block:: python
30   
31   class Root(Controller):
32   
33      def index(self):
34         return "Hello World!"
35   
36
37This completes our simple web application which will respond with
38"Hello World!" when anyone accesses it.
39
40*Admittedly this is a stupidly simple web application! But circuits.web is
41very powerful and plays nice with other tools.*
42
43Now we need to run the application:
44
45.. code-block:: python
46   
47   (Server(8000) + Root()).run()
48   
49
50That's it! Navigate to: http://127.0.0.1:8000/ and see the result.
51
52Here's the complete code:
53
54.. code-block:: python
55   :linenos:
56
57   from circuits.web import Server, Controller
58   
59   class Root(Controller):
60   
61      def index(self):
62         return "Hello World!"
63   
64   (Server(8000) + Root()).run()
65   
66
67Have fun!