GithubHelp home page GithubHelp logo

pkaleta / ewgi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from filippo/ewgi

1.0 2.0 1.0 124 KB

Erlang web gateway interface: a standard interface between Erlang web servers and applications

License: Other

Erlang 100.00%

ewgi's Introduction

EWGI, an Erlang webserver interface specification

EWGI (pronounced you-ghee) is a specification designed to allow web applications written in Erlang to run on any supported server. It also makes developing web applications simpler and more flexible by providing a common mechanism for reusing components. It was inspired by Python's PEP 333 and provides similar functionality to other projects such as Ruby's Rack .

"Hello world!" MochiWeb example

This sample application simply responds with 200 OK and a text/plain entity body of Hello world! for all requests.

Cheers to Geoff Cant for writing this example.

  1. Grab the latest ewgi and MochiWeb source trees.

    $ git clone git://github.com/skarab/ewgi.git
    $ svn checkout http://mochiweb.googlecode.com/svn/trunk/ \
      mochiweb-read-only
    
  2. Compile them.

    $ (cd ewgi/ && make)
    $ (cd mochiweb-read-only/ && make)
    
  3. Create a file called ewex_web.erl

    -module(ewex_web).
    
    -export([start/0,stop/0,
             loop/1,simple_app/1]).
    
    start() ->
        mochiweb_http:start([{name, ewex}, {loop, fun ?MODULE:loop/1},
                             {ip, "127.0.0.1"}, {port, 8889}]).
    
    stop() ->
        mochiweb_http:stop(ewex).
    
    loop(Req) ->
        Mod = ewgi_mochiweb:new(fun ?MODULE:simple_app/1),
        Mod:run(Req).
    
    simple_app({ewgi_context, Request, _Response}) ->
        ResponseHeaders = [{"Content-type", "text/plain"}],
        Response = {ewgi_response, {200, "OK"}, ResponseHeaders,
                    [<<"Hello world!">>], undefined},
        {ewgi_context, Request, Response}.
    
  4. Compile it

    $ erlc ewex_web.erl
    
  5. Run

    $ erl -pa ewgi/ebin/ -pa mochiweb-read-only/ebin/ -eval \
    'ewex_web:start(), receive done -> done end.'
    
  6. Point your browser to http://127.0.0.1:8889/ (type halt(). in the Erlang shell when you want to stop)

The even shorter inets example

$ git clone git://github.com/skarab/ewgi.git && (cd ewgi/ && make \
  && erl -pa ebin/ -eval 'application:start(inets)' \
  -eval 'application:set_env(ewgi, app_module, ewgi_test)' \
  -eval 'application:set_env(ewgi, app_function, testapp)' \
  -eval 'inets:start(httpd, [{port, 8889},
                             {server_name, "ewgi"},
                             {server_root, "."},
                             {document_root, "."},
                             {modules, [ewgi_inets]}])')

Middleware components

The real power of the EWGI interface specification is the ability to compose applications so that requests and responses can be modified by reusable components. For example, the specification includes an example middleware component which converts all text responses to upper-case.

Advantages

  • Applications are server independent.
  • Middleware components can be reused.
  • Applications have a clean, functional interface.

Reference implementations

The current server reference implementations include:

ewgi's People

Contributors

hntrmrrs avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.