Today I’ve released Misultin (pronounced mee-sul-teen), an Erlang library for building fast lightweight HTTP servers. The first benchmarks are quite satisfying, even though there still is work to do.
Here is the simple code for Misultin’s Hello World.
-module(misultin_hello_world).
-vsn('0.1').
-export([start/1, stop/0, handle_http/1]).
% start misultin http server
start(Port) ->
misultin:start_link([{port, Port}, {loop, fun(Req) -> handle_http(Req) end}]).
% stop misultin
stop() ->
misultin:stop().
% callback on request received
handle_http(Req) ->
Req:ok("Hello World.").
Here’s the code to echo a GET variable in a XML form.
-module(misultin_get_variable).
-vsn('0.1').
-export([start/1, stop/0, handle_http/1]).
% start misultin http server
start(Port) ->
misultin:start_link([{port, Port}, {loop, fun(Req) -> handle_http(Req) end}]).
% stop misultin
stop() ->
misultin:stop().
% callback on request received
handle_http(Req) ->
% get params
Args = Req:parse_qs(),
Value = proplists:get_value("value", Args),
case Value of
undefined ->
Req:ok([{"Content-Type", "text/xml"}], "no value specified ");
_ ->
Req:ok([{"Content-Type", "text/xml"}], "~s ", [Value])
end.
Available also are additional code examples, and the full list of exports.
You may find Misultin, released under the New BSD License, on its project page on Google code.
No comments yet.