GROWI, an open-source in-house wiki, has a public REST API. To make this API easier to use, we are developing a TypeScript/JavaScript SDK. It is still in progress, but we will gradually add more functions.
This article will explain how to perform CRUD (Create, Read, Update, Delete) operations on pages.
Notes
This is a community SDK. Please refrain from contacting the official.
Source code
The source code of GROWI TypeScript/JavaScript SDK is available on GitHub. The license is MIT.
Installation
Installation is done via npm/yarn.
$ npm install @goofmint/growi-js
# or
$ yarn add @goofmint/growi-js
Usage
First, import the SDK.
const { GROWI } = require('@goofmint/growi-js');
// or
import { GROWI } from '@goofmint/growi-js';
Then, initialize it. At this point, we specify the API token for GROWI.
const growi = new GROWI({ apiToken: 'your-api-token' });
In addition, the following parameters are provided.
-
url
: URL of GROWI. The default ishttp://localhost:3000
. -
path
: specifies the page path of GROWI. The default is '' . Specify when installing in a subdirectory.
Get page
Currently, getting pages from the root is supported. The return value is a Page
object.
const page = await growi.root();
The page body is retrieved using the contents
method.
const contents = await page.contents();
Get child pages
Use the children
method to retrieve child pages. This is an array of Page
.
const children = await page.children();
Update body text
To update the body, apply the body to the contents
method. Then, call the save
method.
page.contents('new body');
await page.save();
Create a new page
To create a new page, use the create
method.
const newPage = await growi.create({name: 'new page'});
When created, the body
parameter can be used to specify the page's body, and the grant
parameter can be used to specify the scope of the publication.
const newPage = await page.create({ name, grant: growi.Page.Grant.public });
Remove a page
Use the remove
method to remove a page.
await page.remove();
The optional parameter isCompletely
will physically remove the page. If isRecursively
, child pages are also removed recursively.
Summary
As an in-house wiki, GROWI will likely need data linkage with in-house systems. Please use the Node.js SDK to operate GROWI from your system.
GROWI, an OSS development wiki tool | comfortable information sharing for all
Top comments (0)