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

Joe Armstrong (AL/EAB) joe.armstrong@REDACTED
Wed Jun 14 11:54:32 CEST 2006


 
> From: Gaspar Chilingarov
> Sent: den 13 juni 2006 23:23
 
[cut]

> 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
tuple
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
www.some.server

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
store.

What does the code look like for the login page?

	<title>Login</title>

	<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} 
tuple.

   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
let's 
define a protocol on top of HTTP which does this:

    This request updates the tuple store:

	http://www.some.server/put/joe/login/region?val=EncodedString

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


      http://www.some.server/get/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
any
	   region on the page is updated)

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

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

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

Extensions extensions .....


Authentication
==============

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

here we can use (say) RSA

	
http://www.some.server/put/joe/login/mood?val=happy&auth=ag234zs12321

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?

	htpp://www.some.server/pleaseTellmeWhenChanged/joe/login/mood?
key=ghajgdjagd128731
               & site=www.foo.bar/put/agregator/changed/inbox

      => Ok | refused

      So when the tuple (joe,login,mood) was changed the server would do
a
	
	 
	http://www.foo.bar/put/agregator/chanded/inbox?val=EncodedString
? key=...


 etc.

Let's try and formalise this:

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

   API   create_tuple_store()
	   create_tuple(Who, Page, Region, PriKey, PubKey) => ok | error
string
	   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

	http:/www.some.site/put/who/page/region?val=...&auth=....

	http://www.some.site/get/who/page/region



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

   (example)

		<h1>hello</h1>

		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
 
Finally.

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 

http://www.erlang.org/examples/examples-2.0.html

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

/Joe



More information about the erlang-questions mailing list