from __future__ import *

mochiweb - another faster web server

November 07, 2007 at 09:39 PM | categories: mochiweb, erlang | View Comments

mochiweb is finally well on its way to becoming a proper open source project, thanks to Matthew Dempsky. We've got a mochiweb project on google code and a mochiweb group on google groups.

Similarly interesting is that iserve is now turning into something more useful. iserve and mochiweb are pretty much the same thing under the hood, but mochiweb exposes a different API (which I find to be nicer, but I designed it) and supports more of the HTTP protocol. They both (ab)use inets' {packet, http} mode and they're both very minimal.

Here's a mochiweb version of the minimal example that Tobbe gave for iserve:

-module(mochiweb_demo).
-export([mochiweb_request/1, start/1]).

start(Port) ->
    mochiweb_http:start([{port, Port}, {loop, {?MODULE, mochiweb_request}}]).

mochiweb_request(Req) ->
    Req:ok({"text/html",
    <<"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
        <html>
        <head><title >Welcome to mochiweb</title></head>
        <body>
            Hello
        </body>
        </html>">>}).
blog comments powered by Disqus