Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Mochiweb/Webmachine

by Flavio Ishii
Mochiweb
• An Erlang library for building light-weight HTTP
servers.
• Provides manipulation of resources via HTTP
methods: GET/POST/PUT/DELETE.
• Good for large number of lightweight req/resp.
• MIT Licensed.
• Facebook Chat.

Flavio Ishii, Sept. 17, 2009


Mochiweb
• Good for serving large number of
lightweight processes.
• Quick setup
• Easy maintenance
• Examples: Facebook Chat

Flavio Ishii, Sept. 17, 2009


Webmachine
• Built on top of Mochiweb.
• Not quite a framework but an HTTP Toolkit for
lightweight REST servers.
• Open source project developed by Basho
Technologies.
• Key concepts:
• HTTP Gateway
• Resource is mapped to function set
• Overwrite default resource function and keep
passing the puck (or Erlang term)
• f(ReqData,Context)->{Result,ReqData,
Context}
Flavio Ishii, Sept. 17, 2009
Webmachine Installation
Download package from the web or:
$ hg clone http://bitbucket.org/justin/
webmachine/ webmachine-read-only

$ cd webmachine-read-only

$ make

Flavio Ishii, Sept. 17, 2009


Webmachine Skeleton
Create, build, and start the skeleton resource:
$ ./scripts/new_webmachine.erl mywebdemo /tmp

$ cd /tmp/mywebdemo

$ make

$ ./start.sh
Try creating a Webmachine API
• Create a Webmachine app.
• Follow the instructions given here
http://bitbucket.org/justin/webmachine/wiki/ExampleResources
• Use Mnesia files from my Mnesia tutorial
slides to and create a Webmachine user
resource.
• Create function set for resource.
• Test with curl commands.
• Use wmtrace tool to visualize the path
taken by the HTTP request. Flavio Ishii, Sept. 17, 2009
Webmachine Features

• Authentication
• etag: http caching
• Integrates well with Riak (A
Decentralized JSON Web Database,
also from Basho Technologies)
• Collecta’s API is built in Webmachine

Flavio Ishii, Sept. 17, 2009


Resources

• http://code.google.com/p/mochiweb

• http://bitbucket.org/justin/webmachine/wiki

• http://blog.therestfulway.com

• http://basho.com

Flavio Ishii, Sept. 17, 2009


Contact Info

USASK - MADMUC Lab


http://flavioishii.com
@flavioishii

Flavio Ishii, Sept. 17, 2009

You might also like