Web pages using a simple tuple store [was : RE: template engine]

Joe Armstrong (AL/EAB) <>
Wed Jun 14 11:54:32 CEST 2006

> From: Gaspar Chilingarov
> Sent: den 13 juni 2006 23:23

> I would like to listen any suggestions on templating 
> solution, which you would like to see - even too fantastic or 
> futuristic -- because it's always possible to find something 
> reasonable and practical there.
Thinking out loud ... I've been thinking about this for a couple of
years ... 

I actually rather like the result - it combines a distributed object
store with web pages and removes the need for complex data base tables
and configuration.

So ...

Can we abstract out the data base in a web application?

Yes - here's how.

Imagine a site www.some.server

There are some  users (joe, gaspar, fred ... )

There are some web pages (login, main, chat ...) 

The web pages have *regions* (new concept here) :-)
with names like (inbox, mood, status)

These three things define a key in a tuple store associated with

The values of the regions are strings

	Example: the key ("joe", "login", "mood") in the tuple store on
	www.some.server currently contains the string "happy"

When joe requests the page called "login"  he gets a different page
to gaspar. The VALUES of the regions in the web page come from the tuple

What does the code look like for the login page?


	<h1>Hello <? get(?Who, login, owner) ?>

	<p>My mood is <? get(?Who, login, mood) ?>

Here ?Who is "joe"

To implement this all we need is a persistent tuple store.

   get(Who, Page, Region) return the value of the {Who, Page, Region} 

   Getting values out of the tuple store is easy, just use the function
get(Who, Page, Region).

   Putting values into the store is also easy
(if we ignoring security, which I'll deal with later)

    To put a value in the tuple store we evaluate

	put({Who,Page,region}, Value)

    But this is a *local* operation - let's make this distributed, and
define a protocol on top of HTTP which does this:

    This request updates the tuple store:


    It returns the OLD value of the tuple (joe,login,region)


    Retrieves the value of the (joe,login,region) tuple

What is the behaviour of get and put?

How about:

	1) put is persistent
	2) If a user is viewing a page and sombody put's a new value
	   the change is seen immediately (this needs an ajax lister,
	   for every page, it rpc the server and gets a return value if
	   region on the page is updated)

Now the tuple store is just a function from a 3 tuple of strings to a
ie of type string x string x string -> string.

HOW the tuple store is implemented is irrelevant (use mnesia, mysql,

Note we also don't need to define any data base tables.

Extensions extensions .....


Authentication: Who can do a put? - anybody, the "owner" of the data,
some trusted

here we can use (say) RSA


and require that the value is signed with an appropriate key -
unfortunately RSA is
pretty heavyweight - so I'd welcome suggestions here for a
lighter-weight method.

RSS feeds

	Suppose you'd like to know when a region was updated?

               & site=www.foo.bar/put/agregator/changed/inbox

      => Ok | refused

      So when the tuple (joe,login,mood) was changed the server would do
? key=...


Let's try and formalise this:

1) Every web site has a tuple store with keys of type string x string x

   API   create_tuple_store()
	   create_tuple(Who, Page, Region, PriKey, PubKey) => ok | error
	   put_val(Who, Page, Region, NewVal, Auth) => bool 
	   get_val(Who, Page, Region) => Val | "error"
	   is_authorised(Who, Page, Region, Val, Auth) => bool
	   get_pub_key(Who, Page, Region) => Pubkey
	   sign(Val, PriKey) => Auth

2) put_val and get_val can be accessed by HTTP requests



3) Web page writers can get tuple values using the following syntax



		Welcome <? get(?Who, ?Page, owner) ?> you have been here
	      <? get(?Who, ?Page, visited) ?> times

	The meta variable Page is the page name - Who is the owner

I don't have time to implement this tonight - the Mother-in-law is
coming to
stay (for two weeks) and there are a number of distractions coming up
like Holidays - where I'm expected to "enjoy myself" - so feel free to
implement this.

If Luke or Tobbe is reading - I'll expect a complete implementation by
return of post.

Hint: RSA in Erlang can be run of-of-the box

Just read 


There's a link to the code tarball on this page - RSA is included
(uses Erlang bignums :-)


More information about the erlang-questions mailing list