Wiki

Clone wiki

webcandy / o_one

StickyNotes + WebMachine. Initial merge.

Release 0.1 features

  1. GET and POST requests are controlled by separate resources, one to serve static files and another one to serve the notes data
  2. The newest Webmachine stores Dispatch in the priv/dispatch.conf, so to serve static files smoothly the extra routine was added to the supervisor
  3. The very StickyNotes app was left intact, both the client and the server parts.
  4. Last, but not least, the home page now is a data exchange client, which allows you to see and control the requests in detail, much like in Curl, but using plain HTML form with Javascript.

HTTP client

Next steps?

  1. pass the read-only action read_all through the GET. For that the client portion of the StickyNotes needs to be slightly updated.
  2. add some authentication mechanism to allow different layers of access.
  3. add ETAG generation and analysis to help prevent concurrent content updates.
  4. replace the basic "notes" functionality by ... virtually anything

JSON - notes

The priv/dispatch.conf looks like

{["notes"], webmstn_dynamic_resource, []}.
{['*'], webmstn_static_resource, ['PATHTOWWW']}.

The first line matches only the access path /notes, the JSON "notes" exchange will go through the "dynamic" channel. Currently, it accepts only POST: the resource src/webmstn_dynamic_resource.erl has only one allowed method:

allowed_methods(RD, Ctx) ->
    {['POST'], RD, Ctx}.

Static Files: The Supervisor.

the static requestsmatch the second row in the dispatch.conf and will be served by the webmstn_static_resource. The supervisor replaces the atom 'PATHTOWWW' by the actual absolute path to the priv/www in the function prep_dispatch, called by init:

%% in the webmstn_sup.erl:
prep_dispatch(DispatchTemplate) -> 
    WWWPath = filename:absname("priv/www"),
		    lists:map(fun({Pattern,Resource,Paths})->
                				 {Pattern, Resource,
						     lists:map(fun(Code) ->
									if 
										Code =:= 'PATHTOWWW' -> WWWPath;
										true                 -> Code
									end
								end, Paths)} 
				end, DispatchTemplate ).

Static Files: The Resource.

The only accepts GET and heads. We are using the default interface in the parametrized module webmachine_resource, so there is no need to write our own version:

%% in the deps/webmachine/webmachine_resource.erl
default(allowed_methods) ->
    ['GET', 'HEAD'];

Go ahead and try

Download Release 0.1

Updated