Erlang and Webmachine
I'm currently working on a small startup project, for one to meet a need of some acquaintances, but more importantly to learn me some Erlang with regards to the web. While I'm further along than I actually expected to be, I thought I'd begin documenting the steps I've taken towards building this app. The current nerdities I'm using:
- Emacs - Editor of choice
- Erlang - Functional programming language
- Webmachine - REST toolkit
- CouchDB - Document store
- Couchbeam - Couchdb framework for Erlang
- ErlyDTL - Templating engine
- ESTMP - Email sending
- Tsung - Stress-testing
Installation of all of these on a GNU/Linux system is pretty straightforward, so I won't cover that here. Defaults were used for Erlang. I installed the other libraries/applications in ~/dev/erlang/lib and pointed $ERL\LIBS there in my .bashrc. I did follow this guide for setting up Tsung. The BeeBole site has several other pages worth reading for developing web applications in Erlang. Once installed, build the webmachine project:
$WEBMACHINE_HOME/scripts/new_webmachine.erl wm_app /path/to/root cd /path/to/roow/wm_app make ./start.sh
You now have a working project! Of course, I like to have my Erlang shell inside of emacs while I'm developing, so I added a comment to the start.sh script that contained the shell parameters. My start.sh looks like this:
#!/bin/sh # for emacs C-c C-z flags: # -pa ./ebin -pa ./priv/templates/ebin -boot start_sasl -s wm_app cd `dirname $0` exec erl -pa $PWD/ebin $PWD/deps/*/ebin $PWD/deps/*/deps/*/ebin $PWD/priv/templates/ebin -boot start_sasl -s wm_app
I currently have all of my dependencies in $ERL\LIBS; when I deploy this to production, I'll add the libs to the wm\app/deps as either a symlink or copied into the directory. To have the custom shell means you need the .emacs code to start an Erlang shell with custom flags. Important note: If you need to specify multiple code paths in the -pa arg, you have to use a -pa for each path, unlike in the shell command version where any path after the -pa (or -pz) is added. Another caveat: when starting the Erlang shell within emacs, if you're currently in a erlang-related buffer (.erl, .hrl, etc), the default shell is started without the option to set flags. I typically have the start.sh open anyway to copy the flags so I don't run into this much anymore; I'm documenting it here just in case anyone stumbles on it. Now you have a shell within which to execute commands against your webmachine app, load updated modules, etc. Coming up, I'll talk about how I'm using ErlyDTL to create templates and using CouchDB/Couchbeam for the document store.