Wiki API

Here we look at some useful javascript calls that the wiki-client can interpret. The examples on this page can be experimented with by typing them as is into your browsers javascript console.

Not an API yet perhaps. But in a federation of decentralised components some sort of API is needed. here we can start to ask this question.

# Web messaging

Web messaging is a way for documents in separate browsing contexts to share data without the DOM being exposed to malicious cross-origin scripting. Unlike other forms of cross-site communication, web messaging never directly exposes the DOM -

# My wiki talks to your wiki

We anticipate creating an api for the wiki-client using window.postmessage. This would require defining the following type of event listener in the client:

//respond to events window.addEventListener('message',function(event) { if(event.origin !== '') return; console.log('message received: ' +,event); event.source.postMessage('holla back youngin!',event.origin); },false);

This would enable web pages to embed wiki as an iFrame, or wiki to communicate to or be communicated with other apps in browser tabs or wasm components.

# Avoiding being pushy

The federation looks to avoid push. This causes us a great deal of problems. It prevents wiki becoming famous or rich. But it achieves an invaluable form of protection from the most common forms of malware. It provides us an affordable harbour.

# Navigation

Let's navigate to an internal page on the site:


Remote Links can be navigated to using the same syntax with additional parameters:

wiki.doInternalLink('folder', null, '')

The external link is handled in wiki.resolveLinks which handles both internal and external links in a block of text. The code is in github

# Creating Ghost Pages

Let's display a "hello world" ghost-page:

wiki.showResult(wiki.newPage({title:'hello world'}))

Should we wish to accept json from an external source:

var pageJson = '{"title":"Ghost Page"}'; var pageArray = JSON.parse(pageJson); wiki.showResult(wiki.newPage(pageArray));

# Fetching Pages

Let's fetch a page with javascript and display it as a ghost-page:

let page = await fetch('').then(res => res.json()) wiki.showResult(wiki.newPage(page))

Alternatively without using `await`:

fetch('') .then(res => res.json()) .then(json => wiki.showResult(wiki.newPage(json)))

Let's fetch a page with wiki-client javascript. You need to construct some javascript of the form:'site').get('page', cb())

An example with a callback that calls `console.log`:'').get('welcome-visitors.json', (page) => console.log(page))

There are actually two callback parameters:'').get('welcome-visitors.json',(err,page)=>wiki.showResult(wiki.newPage(page)))

# Search

let's use wiki-client to construct an array based on searching the neighborhood:'how to')

Here is the code we use to format a search result as a ghost page: -

# Info

Let's find out what wiki-client nows about the wiki-site:

Let's identify the first roster in the lineup:'')


# See also