I'm not sure how to resolve this, some comments within.
On Tue, 8 Apr 2014, Jeremy Ruston wrote:
More to the point, there is support for users creating and using JSON
tiddlers.
I think part of the problem here is the the term "tiddler" has become
quite diverse in meaning, especially when it gets mixed between the
abstract idea of a tiddler and representations of that idea.
The clearest way to see the issue here is:
* PUT a tiddler with content-type application/json, with type of
application/json and text which _is_ JSON:
curl -X PUT \
-H "Content-Type: application/json"
http://0.0.0.0:8080/bags/common/tiddlers/f1 \
--data-binary '{"type": "application/json", "text": "{\"text\": \"foo\"}"}'
* GET that tiddler as application/json:
curl -v \
-H "Accept: application/json"
http://0.0.0.0:8080/bags/common/tiddlers/f1
The output will be:
{"text": "foo"}
Then compare with:
* PUT a tiddler with content-type application/json, with no type and
text which _is_ JSON:
curl -X PUT \
-H "Content-Type: application/json" \
http://0.0.0.0:8080/bags/common/tiddlers/f2 \
--data-binary '{"text": "{\"text\": \"foo\"}"}'
* GET that tiddler as application/json:
curl -v \
-H "Accept: application/json" \
http://0.0.0.0:8080/bags/common/tiddlers/f2
The output will be:
{"creator": "GUEST", "fields": {}, "created": "20140408125125",
"recipe": null, "modified": "20140408125125", "uri":
"http://0.0.0.0:8080/bags/common/tiddlers/f2", "bag": "common",
"text": "{\"text\": \"foo\"}", "title": "f2", "permissions":
["read", "write", "create", "delete"], "modifier": "GUEST", "type":
null, "tags": [], "revision": 1}
This mechanism is true of any media type pairing. If you PUT a JSON
tiddler with type 'application/javascript' and GET it as
'application/javascript' you will get back just the javascript.
curl -X PUT \
-H "Content-Type: application/json" \
http://0.0.0.0:8080/bags/common/tiddlers/f3 \
--data-binary '{"type": "application/javascript", "text": "alert(\"hi\")"}'
curl -H "Accept: application/javascript" \
http://0.0.0.0:8080/bags/common/tiddlers/f3
alert("hi")
From the semantics of the HTTP API this makes sense.
Right. But one wouldn't expect that a consequence of deciding to try
putting structured data in a tiddler would be to change the retrieval
behaviour (I would expect it to change the rendering behaviour, but I think
that's different).
One might not expect it, but it is how it has worked for several
years and is aligned with the semantics of the API with regard to
tiddlers that want to "override" the value of the text field[1].
A quick fix is to set a different type field (not application/json) on
the JSON generated before being PUT to the server (with content-type
application/json) and then reverse that mapping when the tiddler is
being processed.
We could perhaps do it for plugins (at a ridiculous cost; we've got plugins
with hundreds of tiddlers in them). But it wouldn't solve the problems for
the other cases of JSON being stored in tiddlers.
No, indeed that doesn't sound great.
All I need is a reliable way to read the text and fields of a tiddler,
regardless of its content type.
I think the best thing is going to be to set the 'type' field to
something different. There's already the "unholy freaking of content
types" in tiddlywebadaptor.js so there's some precedent.
It's not ideal but is probably workable and keeps the (I think
important) distinction between the content-type of the representation
being PUT and the media type of the content.
Is that workable?
[1] I guess the underlying cause of issues here is how the "text"
attribute is being used across the various representations and
contexts. TiddlyWeb optimizes for a short code path and a flexible
default web representation for single tiddlers that want to declare
arbitrary content types. This is okay for single web requests of the
"content" but comes at the cost of lost metadata on some of those
requests and weirdness when dealing with "content" which is JSON.
--
Chris Dent http://burningchrome.com/
[...]
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.