Is it possible to create alternative REST APIs from inside the TiddlyWiki webpage?

154 views
Skip to first unread message

Rafael Oliveira

unread,
Jul 31, 2020, 2:09:38 AM7/31/20
to TiddlyWiki
I've seen that TW has a REST API with 10 different funcionalities:
  • Delete Tiddler
  • Force Basic Authentication Login
  • Get All Tiddlers
  • Get Favicon
  • Get File
  • Get Rendered Tiddler
  • Get Server Status
  • Get Tiddler
  • Get Wiki
  • Put Tiddler
Taking into consideration all the different filters we can create inside TW, I was thinking that creating alternative APIs could be useful at some point for me. However, I'm in doubt if this is possible. Can I create a new REST API with a tiddler that will deliver to a client the results of a TW macro? In my case I use the node.js version... Would I have to develop backend code that is outside the TiddlyWiki page to create new APIs?


If this is possible from inside the TW page... I'd like some directions on what are the topics I should be looking to make it happen...

Saq Imtiaz

unread,
Jul 31, 2020, 2:18:33 AM7/31/20
to TiddlyWiki
I am not clear on precisely what you want to do here regarding macros. However, you can write JavaScript in tiddlers that will run on the backend under node.js.
See the following for an example of adding a new route to the server:

https://saqimtiaz.github.io/sq-tw/sandbox.html#%24%3A%2Fsq%2FServerRoutes%2Fpost-upload

This is adapted from code from Bob, so there may be other examples to be found there:
https://github.com/OokTech/TW5-Bob

It may also be instructive to look at the code for the render command:

All of this pre-supposes fluency with JavaScript.

Rafael Oliveira

unread,
Jul 31, 2020, 4:57:47 PM7/31/20
to tiddl...@googlegroups.com
Thanks Saq,

I've checked the TW5-Bob page and it tells that I can even run shell commands with it. I think that'll solve my problem, I'll experiment a bit with it to see what I manage to create :)


I am not clear on precisely what you want to do here regarding macros.

Actually, by now I just want to add the functionalities of renaming tiddlers and filtering some of them according to their name... I think it'd be perfectly possible to do that by creating a script that uses the .tid files as input. But I'm not really sure if that would be a sustainable solution in the long term. TiddlyWiki seems to have a very good infrastructure inside it. So I'm assuming that the extra API solution would give me more benefits after I start getting more confidence on what I can do inside TiddlyWiki that's related to automated processess. Is that a right assumption?

TW Tones

unread,
Jul 31, 2020, 7:43:59 PM7/31/20
to TiddlyWiki
Rafael,

A great deal can be done inside tiddlywiki without reverting to server and command lines. This can be done nativelly however various tools abound like Mohammad's commander.

Regards
Tony 

Rafael Oliveira

unread,
Aug 1, 2020, 12:29:31 AM8/1/20
to tiddl...@googlegroups.com
Hi Tones,

I've asked about the REST API because I'd like to make TiddlyWiki gives the information of my notes to a different external application.

I'm not 100% sure if building an API is the only way to do it. My main requirement is that the external application can ask TW for information at any time, so TW needs to deliver it... In my view, the backend integration in this case is necessary, but I may be wrong. Are there alternative frontend solutions for this case?

TW Tones

unread,
Aug 1, 2020, 3:45:47 AM8/1/20
to TiddlyWiki
Rafael,

I am no expert on this, but if you are using a server version, the tiddlywiki content is already accessible via the server, by definition. Jed has used a similar approach to make Bob wikis multi-access so it locks a tiddler at a time. So there exists a method to query the server already. Perhaps this would be your best approach first. ie investigate either bob server messages" or "native Node.JS".

If you use a single file wiki there are ways to import content from that wiki from elsewhere, but that's not what you are looking for.

My own interest in REST API's is the opposite, and comes from the fact that WordPress already has many API's, custom posts and more. I wonder if a TiddlyWiki could store all its tiddlers in the database behind WordPress in its database via REST API's, in part because such an internet service is easy to obtain. But Then WordPress could also access the tiddler content, a custom post type could even give access to a tiddler independently. We could programaticaly generate wordpress content from a TiddlyWiki.

Best of luck in your endeavours

Remember explaining what you want without a partial solution, may get you further when asking questions.

Perhaps you thought REST API's was the answer, but what was the question? You answered this in part, but the topic title may keep people away.

Regards
Tony

Jed Carty

unread,
Aug 1, 2020, 7:38:03 AM8/1/20
to TiddlyWiki
it sounds like extending the REST api is the way to go with this. Having a script that manipulates the .tid files is possible, but also something like reinventing the wheel. You can rename and filter tiddlers in the node server without building any of the utility functions yourself and then you have the benefit of all the testing and work everyone else has done to ensure stability.

Unless you have something specific to Bob that you need it may be better to use the core tiddlywiki server. Bob doesn't have sufficient security built in to it to be on a public-facing server yet, you would need to have apache or something similar in front of it for security.

And if you use Bob the API routes are a bit different because it has to handle multiple wikis. They follow the same general structure as the core routes but remember the different module type.

Let me know if you need any help.

Rafael Oliveira

unread,
Aug 2, 2020, 3:46:41 PM8/2/20
to tiddl...@googlegroups.com
Thanks everyone for the clarifications,

Jed, sorry about the late silly question... But how could I get started on modifying the TiddlyWiki's core? I'd have to work on the Github version of TiddlyWiki instead of just installing it from the npm repository as I usually do, right? On this GitHub page I only see instructions for starting it from the node.js command line that's created on the system...

I've also discovered the page https://tiddlywiki.com/dev but I'm not so sure if that's where I should be looking for getting started...

In my view, I'd have to download this code and start the node.js application from the command line. Is that the right procedure in this case? Is there a place where I can find documentation on getting started with the core development?
Reply all
Reply to author
Forward
0 new messages