Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Sinatra style web framework for Erlang?

I programmed in Ruby and Rails for quite a long time, and then I fell in love with the simplicity of the Sinatra framework which allowed me to build one page web applications.

Is there a web framework like Sinatra available for Erlang? I tried Erlyweb but it seems far too heavyweight.

like image 899
yazz.com Avatar asked Jan 18 '10 08:01

yazz.com


People also ask

What is the most common Ruby framework?

Back-end web framework Ruby on Rails was developed in 2004 and is one of the most popular Ruby web frameworks. On GitHub, this framework has received over 49,000 ratings. Over 1,060,553 active websites rely on the Ruby framework's solid MVC (Model–view–controller) architecture.

Is Ruby a web framework?

Ruby on Rails (simplify as Rails) is a server-side web application framework written in Ruby under the MIT License. Rails is a model–view–controller (MVC) framework, providing default structures for a database, a web service, and web pages.


2 Answers

You could achieve something minimal with mochiweb:

start() ->
  mochiweb_http:start([{'ip', "127.0.0.1"}, {port, 6500},
                       {'loop', fun ?MODULE:loop/1}]).
                           % mochiweb will call loop function for each request

loop(Req) ->
  RawPath = Req:get(raw_path),
  {Path, _, _} = mochiweb_util:urlsplit_path(RawPath),   % get request path

  case Path of                                           % respond based on path
    "/"  -> respond(Req, <<"<p>Hello World!</p>">>);
    "/a" -> respond(Req, <<"<p>Page a</p>">>);
    ...
    _    -> respond(Req, <<"<p>Page not found!</p>">>)
  end.

respond(Req, Content) ->
  Req:respond({200, [{<<"Content-Type">>, <<"text/html">>}], Content}).

If you need advanced routing, you will have to use regex's instead of a simple case statement.

like image 114
Zed Avatar answered Oct 02 '22 07:10

Zed


Have a look at webmachine. It has a very simple but powerful dispatch mechanism. You simply have to write a resource module, point your URIs to it and your service is automatically HTTP compliant.

like image 21
Tom Sharding Avatar answered Oct 02 '22 08:10

Tom Sharding