/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. Getting Started
  3. ===============
  4. Just like any application or system built with circuits, a circuits.web
  5. application follows the standard Component based design and structure
  6. whereby functionality is encapsulated in components. circuits.web
  7. itself is designed and built in this fashion. For example a circuits.web
  8. Server's structure looks like this:
  9. .. image:: ../images/CircuitsWebServer.png
  10. To illustrate the basic steps, we will demonstrate developing
  11. your classical "Hello World!" applications in a web-based way
  12. with circuits.web
  13. To get started, we first import the necessary components:
  14. .. code-block:: python
  15. from circutis.web import Server, Controller
  16. Next we define our first Controller with a single Request Handler
  17. defined as our index. We simply return "Hello World!" as the response
  18. for our Request Handler.
  19. .. code-block:: python
  20. class Root(Controller):
  21. def index(self):
  22. return "Hello World!"
  23. This completes our simple web application which will respond with
  24. "Hello World!" when anyone accesses it.
  25. *Admittedly this is a stupidly simple web application! But circuits.web is
  26. very powerful and plays nice with other tools.*
  27. Now we need to run the application:
  28. .. code-block:: python
  29. (Server(8000) + Root()).run()
  30. That's it! Navigate to: http://127.0.0.1:8000/ and see the result.
  31. Here's the complete code:
  32. .. code-block:: python
  33. :linenos:
  34. from circuits.web import Server, Controller
  35. class Root(Controller):
  36. def index(self):
  37. return "Hello World!"
  38. (Server(8000) + Root()).run()
  39. Have fun!