Backend protocol in TW5

80 views
Skip to first unread message

joearms

unread,
Feb 18, 2018, 10:07:47 AM2/18/18
to TiddlyWikiDev
Hello,

I'm running the node backend downloaded from https://github.com/Jermolene/TiddlyWiki5
and was wondering exactly what the protocol between the browser and backend was.

At a guess it's JSON over HTTP (I might be wrong) - is the protocol *specified* somewhere
or do I have to read the code (if so where?)

Is there a way of tracing and dumping to a file all the messages between the browser and node
so I can see exactly what is happening?

Cheers

/Joe


Jeremy Ruston

unread,
Feb 18, 2018, 6:02:00 PM2/18/18
to TiddlyWikiDev
Hi Joe

I'm running the node backend downloaded from https://github.com/Jermolene/TiddlyWiki5
and was wondering exactly what the protocol between the browser and backend was.

The TW5 client (contained in the plugin $:/plugins/tiddlywiki/tiddlyweb) talks to the server with the TiddlyWeb API, a flexible API for putting tiddlers on the web. It was originally developed for TiddlyWiki Classic, and is documented at http://tiddlyweb.com/.

The TW5 server (contained in the core plugin) supports a bare minimum of the TiddlyWeb API for personal use.

At a guess it's JSON over HTTP (I might be wrong) - is the protocol *specified* somewhere
or do I have to read the code (if so where?)

It is indeed a traditional RESTesque JSON over HTTP interface.

The client end of the TW5 implementation is here:


And the server end is here:


Is there a way of tracing and dumping to a file all the messages between the browser and node
so I can see exactly what is happening?

Using the browser developer tools “Network” tab gives an excellent insight into what is going on.

Best wishes

Jeremy.


Cheers

/Joe



--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/3214cda4-fcc3-478c-afc1-01be9b5fb359%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

joearms

unread,
Feb 19, 2018, 8:12:46 AM2/19/18
to TiddlyWikiDev

Thanks Jeremy - Actually I did some experiments

I set up a relay server to log all messages between
the Tiddly wiki and the node backend. This is what happened

(Messages always start from the TW - these are the HTTP messages involved)

1) "OPTIONS /"
response 404 Not found

(I had to look up what OPTIONS means - it expects a response something
like Allow: OPTIONS, HEAD, GET, POST)

2) Server closes socket

3) "GET /"
Reply is 200 OK with chunked transfer encoding and a keep alive connection
then we get about 6MBytes of text/html
(I have a question about this response at the end of this mail)

4) "GET /status"
Response is a JSON term
{space:{recipe:default},tiddlywiki_version:"5.1.15"}

5) Server closes socket

6) "HEAD /"
   response 404 Not found

7) GET /recipes/default/tiddlers.json
   Now we get a JSON term with a long list of tidders back

8) PUT /recipes/default/tiddlers/%24%3A%2FStoryList
   Data is a JSON story list
   Response 204 OK

9) Server closes socket

The I did some things in the browser

10) PUT /recipes/default/tiddlers/%24%3A%2FStoryList
   Data is a JSON story list
   Response 204 OK

11) Server closes socket

I did a write in the browser

12) PUT /recipes/default/tiddlers/Draft%20of%20'ProofOfWork
    Data JSON

Other messages include

DELETE /bags/default/tiddlers/Draft%20of%20'ProofOfWork'

PUT /recipes/default/tiddlers/ProofOfWork
data JSON

Enough tracing ...

Comments (and questions)

To make a back-end I need to convert the JSON form of the GETs and PUTs into
a suitable file format.

The tidder ProofOfWork in a file looks like this:

--- 
    created: 20180219090531165
    modified: 20180219090536326
    tags: Silly
    title: ProofOfWork
    type: text/vnd.tiddlywiki

    Energy efficiency is appalling oh

This is slightly different from the JSON term that created the file
The term was

          {created: "20180219090531165",
  text: "Energy efficiency is appalling oh",
  bag: "default",
  revision: "0",
          type: "text/vnd.tiddlywiki",
          title: "ProofOfWork",
          tags: ["Silly"],
          modified: "20180219090535217"}

So the backend has thrown away the bag and revision tags.

The only biggish problem in making a backend is the response to the first
message (the one that results in 6MB of stuff)

Somehow the backend has created a huge page from the data in the file
system.

Is the relationship between the data in the file system and HTML that gets
sent to the browser simple? - ie just the concatenation of a bundle of files
or has the backend done some heavy lifting to make the HTML page?

Cheers

/Joe

PMario

unread,
Feb 19, 2018, 9:34:31 AM2/19/18
to TiddlyWikiDev

joearms

unread,
Feb 20, 2018, 4:33:56 AM2/20/18
to TiddlyWikiDev
I did some more poking around - my current problem is understanding how the first page is built.

It appears that everything starts by expanding $:/core/templates/tiddlywiki5.html

If my backend is not written in JS I'll have to write code code to expand this file.

Question is - is this easy? I guess it depends - hopefully the expander does not do tricky
JS things (this would prevent easy porting to non JS backends)

From the point of view of porting the backend to a different language than node
a pre-computed header would help (ie like a minimal empty.html) page.

Is there a smaller subset of TW5 (ie smaller than empty.html) which 
gets you to the point where only get/put tiddler requests can be processed???

Cheers

/Joe
Reply all
Reply to author
Forward
0 new messages