PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/README.rst

http://github.com/skarab/ewgi
ReStructuredText | 128 lines | 91 code | 37 blank | 0 comment | 0 complexity | 75a0061f327a0278a17efd237fc6c609 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. EWGI, an Erlang webserver interface specification
  2. =================================================
  3. EWGI (pronounced `you-ghee`) is a specification designed to allow web
  4. applications written in Erlang to run on any supported server. It
  5. also makes developing web applications simpler and more flexible by
  6. providing a common mechanism for reusing components. It was inspired
  7. by Python's `PEP 333`_ and provides similar functionality to other
  8. projects such as Ruby's `Rack`_ .
  9. "Hello world!" MochiWeb example
  10. -------------------------------
  11. This sample application simply responds with 200 OK and a
  12. ``text/plain`` entity body of ``Hello world!`` for all requests.
  13. Cheers to `Geoff Cant`_ for writing this example.
  14. #. Grab the latest ewgi and `MochiWeb`_ source trees.
  15. ::
  16. $ git clone git://github.com/skarab/ewgi.git
  17. $ svn checkout http://mochiweb.googlecode.com/svn/trunk/ \
  18. mochiweb-read-only
  19. #. Compile them.
  20. ::
  21. $ (cd ewgi/ && make)
  22. $ (cd mochiweb-read-only/ && make)
  23. #. Create a file called ``ewex_web.erl``
  24. ::
  25. -module(ewex_web).
  26. -export([start/0,stop/0,
  27. loop/1,simple_app/1]).
  28. start() ->
  29. mochiweb_http:start([{name, ewex}, {loop, fun ?MODULE:loop/1},
  30. {ip, "127.0.0.1"}, {port, 8889}]).
  31. stop() ->
  32. mochiweb_http:stop(ewex).
  33. loop(Req) ->
  34. Mod = ewgi_mochiweb:new(fun ?MODULE:simple_app/1),
  35. Mod:run(Req).
  36. simple_app({ewgi_context, Request, _Response}) ->
  37. ResponseHeaders = [{"Content-type", "text/plain"}],
  38. Response = {ewgi_response, {200, "OK"}, ResponseHeaders,
  39. [<<"Hello world!">>], undefined},
  40. {ewgi_context, Request, Response}.
  41. #. Compile it
  42. ::
  43. $ erlc ewex_web.erl
  44. #. Run
  45. ::
  46. $ erl -pa ewgi/ebin/ -pa mochiweb-read-only/ebin/ -eval \
  47. 'ewex_web:start(), receive done -> done end.'
  48. #. Point your browser to ``http://127.0.0.1:8889/`` (type ``halt().``
  49. in the Erlang shell when you want to stop)
  50. The even shorter inets example
  51. ------------------------------
  52. ::
  53. $ git clone git://github.com/skarab/ewgi.git && (cd ewgi/ && make \
  54. && erl -pa ebin/ -eval 'application:start(inets)' \
  55. -eval 'application:set_env(ewgi, app_module, ewgi_testapp)' \
  56. -eval 'application:set_env(ewgi, app_function, testapp)' \
  57. -eval 'inets:start(httpd, [{port, 8889},
  58. {server_name, "ewgi"},
  59. {server_root, "."},
  60. {document_root, "."},
  61. {modules, [ewgi_inets]}])')
  62. Middleware components
  63. ---------------------
  64. The real power of the EWGI interface specification is the ability to
  65. compose applications so that requests and responses can be modified by
  66. reusable components. For example, the specification includes an
  67. example middleware component which converts all text responses to
  68. upper-case.
  69. Advantages
  70. ----------
  71. * Applications are `server independent.`
  72. * Middleware components can be reused.
  73. * Applications have a clean, functional interface.
  74. Reference implementations
  75. -------------------------
  76. The current server reference implementations include:
  77. * `MochiWeb`_
  78. * `Yaws`_
  79. * `inets`_
  80. .. _PEP 333:
  81. http://www.python.org/dev/peps/pep-0333/
  82. .. _Rack:
  83. http://rack.rubyforge.org/
  84. .. _MochiWeb:
  85. http://code.google.com/p/mochiweb/
  86. .. _Yaws:
  87. http://yaws.hyber.org/
  88. .. _inets:
  89. http://erlang.org/doc/apps/inets/http_server.html
  90. .. _Geoff Cant:
  91. http://github.com/archaelus/