Erlang WebDev with WebMachine

Tim McGilchrist (@lambda_foo)


Web Development

Any language worth it's salt needs to provide a web development library or three. anyone? Srsly

General approaches to the web:

What is Webmachine?

"Written in Erlang, Webmachine is an application layer that adds server-side HTTP semantic awareness on top of the excellent bit-pushing and HTTP syntax-management provided by mochiweb, "

WebMachine is not a "framework"!

HTTP is Simple, Right?

Hello World WebMachine style

-export([init/1, to_html/2]).

init([]) ->
    {ok, undefined}.

to_html(ReqData, State) ->
    {"Hello, Webmachine world", ReqData, State}.


WebMachine Layout

Dispatch Rules

Dispatch Example

    {["todos", "*"], sm_todos_resource, []}.

    GET "/todos/12/author"

    "12/author"        => wrq:disp_path
    "/todos/12/author" => wrq:path
    []                 => wrq:path_info
    ["12", "author"]   => wrq:path_tokens


WebMachine is a resource server for the web!

Driven via HTTP methods; GET, PUT, POST, DELETE

Uses correct HTTP status codes.

Well defined place to handle each HTTP method.


A Todo Resource pulled from a demo app.

Example Cont

Problems with POST

ErlDTL Templates

Django style templates for Erlang, similar to JSP and ERB templates.

Building with Rebar

  1. Create a top level rebar.conf
  2. Put in your dependencies
  3. Compile and off you go


You need to provide all the plumbing.
Want to serve JS & CSS, you write the resource.
Authorisation? Callback provided and you write the rest.
DB / ORM? Same.

Get the picture?



One More thing!

Feedback and suggestions for Erlang Factory Lite.