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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With