.STRUM -> DE/TH: The Easy Way to Get REST

October 10, 2005 § Leave a comment

STRUM is still too complex. Can we make it
simpler?

The endgame is always
DE/TH:
Dictionaries
Encoding/Transmitting
HTML
or
DHTML
Encoding/Transmitting
Hashtables
The way to
maximize
your happiness

is to
die
to your happiness

for something bigger than
your
happiness.

Click [Read More] for the
technical description.

DETH is a way to reversibly encode dictionaries
in HTML, such that they can be sent back and forth via HTTP and REST URIs. That
is, every page is both human-readable *and* decomposable into dictionaries which
can trivially be used to invoke it as a web
service.

This can be considered a
microformat allowing machine-processing of Anchors and Forms. For concreteness,
this describes the structures in terms of Python dictionaries, thought the
implementation-side processing is not visible from DETH proper: we never know
what happens on the other side of DETH.
😉

A. Dictionaries (key-value pairs)
are the primary data type

a.
key=value
->
<dt>key</dt><dd>value</dd>
b.
@key=value
->
<dl key=”value”>
c.
@@tag=element,
@@body=content
->
<element>content</element>
? Everything else is a string
? HTML is the serialization of those
dictionaries
? @@tag allows other elements (which ignore
regular/extra key:value
entries)

Example
A.1:

pydict={“@class”:”xoxo”,
“key”:”value”, “a”:”b”} ->

<dl
class=”xoxo”>

<dt>key</dt><dd>value</dd>
<dt>a</dt><dd>b</dd>
</dl>

Example
A.2:

pydict={“@@tag”:”a”,
“@href”:”http://www.opendarwin.org/&#8221;, “@@body”:”%40opendarwin”, “a”:”b”}

-> < a
href=”
http://www.opendarwin.org/“>@opendarwin<
/a>

->
@opendarwin

B.
Lists are a supporting data type. Two forms:

a. “key=[list]”
b. “@@order=[list]”
? Default to “ol” (ordered list) (use
‘@@tag’ for “ul”).
? Items encoded as
“<li>
item</li>”
? If second form, ignore all [other] non-@
keys
? If @@tag = ‘dl’, order keys according to
@@order

Example
B.1:

pylist=[“a”,”b”,”D”,”c”]
pydict1={“key”:
pylist}


->

<dl>
<dt>key</dt><dd><ol>
<li>”a”</li><li>”b”</li><li>”D”</li><li>”c”</li>
</ol></dd>
</dl>

Example
B.2:

pydict2={“@@tag”: “ul”,
@@order=pylist}
->

<ul>
<li>”a”</li>
<li>”b”</li>
<li>”D”</li>
<li>”c”</li>
</ul>

C.
Tables are extended
lists:

<table><tr><td>

1. Column-wise form:
?
@@order
specifies columnal header (<th>)
cells
?
@@body
specifies list of data
dictionaries
2. Grid-wise form:
?
@@order
is empty
?
@@body
is list of lists (all same
size)

Example
C.1:

pyorder=[“c”,”b”,”a”]
pydata=[
{“a”:”apple”,”b”:”banana”,”c”:”cantaloupe”},
{“b”:”bus”,”a”:”auto”,”c”:”car”}]

pydict={“@@tag”:”table”,
“@@body”: pydata, @@order=pylist}

->
<table>
<tr><th
scope=”col”>c</th> <th scope=”col”>b</th> <th
scope=”col”>a</th></tr>

<tr><td>cantaloupe</td><td>banana</td><td>apple</td></tr>
<tr><td>car</td><td>bus</td><td>auto</td></tr>
</table>

Example
C.2:

pydata=[
[71,89,17],[Ê5,59,113],[101,29,47]]

pydict={“@@tag”:”table”,
“@@body”: pydata}

->
<table>
<tr><td>71</td><td>89</td><td>17</td></tr>
<tr><td>5</td><td>59</td><td>113</td></tr>
<tr><td>101</td><td>29</td><td>47</td></tr>
</table>

D.
Forms are special
tables:

<form><label><input>

Example
D.1:

pyorder=[“name”, “sex”,
“submit”,
“reset”]

pydict={“@@tag”:”form”,
“@action”:”http://somesite.com/adduser“,
“@method”:”post”,
“@@order”:pyorder

name:”Name:
“,

“sex”:{“@@body”:”Sex: “,@type=”radio”,
“male”:”Male”,”female”:”Female”},


“age”:{@type=”select”, “child”:”<
18″,”adult”:”18-64″,”senior”:”65+”},


“submit”:”Send”,


“reset”:””,

}

->
<form
action=”http://somesite.com/adduser
method=”post”>

<label
for=”name”>Name: <input type=”text” id=”name”
/></label>

<label
for=”sex”>Sex:

<input type=”radio”
name=”sex” id=”sex”
value=”male”>Male</input>


<input type=”radio” name=”sex” id=”sex”
value=”female”>Female</input>


</label>

<select
name=”age”>

<option
value=”child”>&lt 18</option>


<option
value=”adult”>18-64</option>


<option
value=”senior”>65+</option>


</select>

<input type=”submit”
value=”Send”>

<input
type=”reset”>

</form>

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

What’s this?

You are currently reading .STRUM -> DE/TH: The Easy Way to Get REST at iHack, therefore iBlog.

meta

%d bloggers like this: