Commits

sunneach  committed 6ae7f6f

otwo

  • Participants
  • Parent commits bd6d581

Comments (0)

Files changed (3)

 This is a successful attempt to compile StickyNotes ([[http://beebole.com/en/blog/erlang/tutorial-web-application-erlang/|Hughes Waroquier from BeeBole]]), keeping in mind the [[http://blog.therestfulway.com/2008/10/beebole-erlangweb-tutorial-webmachine.html|remarks]] of [[http://bitbucket.org/justin/webmachine/wiki/Home|Justin Sheehy]].
 The [[http://webmachine.googlecode.com/files/webmachine_stickynotes.tar.gz|initial compilation ]] was done by <<user justin>> for the "original" Webmachine release, and the current project is using the latest Webmachine - younger than 1.0. There are essential calling convention changes which needed to be taken care of.
 
-=== In Brief ===
-# GET and POST requests are controlled by separate resources, one to serve static files and another one to serve the //notes// data
-# The newest Webmachine stores Dispatch in the priv/dispatch.conf, so to serve static files smoothly the extra routine was added to the supervisor
-# The very StickyNotes app was left intact, both the client and the server parts. 
-# 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.
+* The StickyNotes is now [[RESTFul!|o_two]] it took a bit to add PUT/DELETE to application.js and change the notes:read. More on updates [[o_teo|here]].
 
-{{HTTPclientsm.png|HTTP client}}
+|! HTTP Method |! Is Used For |! The URL |! Comment |
+| GET | initial read of all notes | /notes/all | GET notes/123 does give you the individual record, but the StickyNotes does not use that|
+| PUT | update the note | e.g. /notes/12 | the note ID is generated on the server, so we use POST for creates |
+| DELETE | delete the notes | /notes/7 | /notes/all will just return OK for now |
+| POST | create a new note | /notes | the initial note attributes are submitted from the browser |
 
-=== Next steps? ===
-# pass the read-only action //read_all// through the GET. For that the client portion of the StickyNotes needs to be slightly updated.
-# add some authentication mechanism to allow different layers of access. 
-# add ETAG generation and analysis to help prevent concurrent content updates.
-# replace the basic "notes" functionality by ... virtually anything
-
-
-=== More Light ===
-
-==== JSON - notes ====
-
-The //priv/dispatch.conf// looks like
-{{{
-#!erlang
-{["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:
-{{{
-#!erlang
-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:
-{{{
-#!erlang
-%% 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:
-{{{
-#!erlang
-%% in the deps/webmachine/webmachine_resource.erl
-default(allowed_methods) ->
-    ['GET', 'HEAD'];
-}}}
-
-==== The Test Home Page ====
-
-The http://localhost:8000 is now pointing to a small client page //priv/www/index.html// which allows you to 
-  * explicitly enter JSON, 
-  * choose between GET/PUT/HEAD...
-  * select Content-Type either //application/json... // or application/x-www-urlencoded //
-
+** The HTTP PUT is called to update note attributes;
+** The HTTP  is used to read all notes
+** The HTTP GET is used to read all notes
+* The initial working version 0.1 is described [[o_one.wiki|here]]. There was only mininal change set, just to get the StickyNotes work on WebMachine.
 
 ==== Go ahead and try ====
 

File images/HTTPclient.png

Removed
Old image
+=== In Brief ===
+# GET and POST requests are controlled by separate resources, one to serve static files and another one to serve the //notes// data
+# The newest Webmachine stores Dispatch in the priv/dispatch.conf, so to serve static files smoothly the extra routine was added to the supervisor
+# The very StickyNotes app was left intact, both the client and the server parts. 
+# 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.
+
+{{HTTPclientsm.png|HTTP client}}
+
+=== Next steps? ===
+# pass the read-only action //read_all// through the GET. For that the client portion of the StickyNotes needs to be slightly updated.
+# add some authentication mechanism to allow different layers of access. 
+# add ETAG generation and analysis to help prevent concurrent content updates.
+# replace the basic "notes" functionality by ... virtually anything
+
+
+=== More Light ===
+
+==== JSON - notes ====
+
+The //priv/dispatch.conf// looks like
+{{{
+#!erlang
+{["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:
+{{{
+#!erlang
+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:
+{{{
+#!erlang
+%% 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:
+{{{
+#!erlang
+%% in the deps/webmachine/webmachine_resource.erl
+default(allowed_methods) ->
+    ['GET', 'HEAD'];
+}}}
+
+==== The Test Home Page ====
+
+The http://localhost:8000 is now pointing to a small client page //priv/www/index.html// which allows you to 
+  * explicitly enter JSON, 
+  * choose between GET/PUT/HEAD...
+  * select Content-Type either //application/json... // or application/x-www-urlencoded //
+
+
+==== Go ahead and try ====
+
+{{{
+$ hg clone http://bitbucket.org/sunneach/webcandy/wiki/
+}}}