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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
-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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
-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.