DEV Community

Atsushi
Atsushi

Posted on • Updated on

Introduction to GROWI TypeScript/JavaScript SDK (Part 1: CRUD operations on pages)

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.

goofmint/growi-sdk-alpha

Installation

Installation is done via npm/yarn.

$ npm install @goofmint/growi-js
# or
$ yarn add @goofmint/growi-js
Enter fullscreen mode Exit fullscreen mode

Usage

First, import the SDK.

const { GROWI } = require('@goofmint/growi-js');
// or
import { GROWI } from '@goofmint/growi-js';
Enter fullscreen mode Exit fullscreen mode

Then, initialize it. At this point, we specify the API token for GROWI.

const growi = new GROWI({ apiToken: 'your-api-token' });
Enter fullscreen mode Exit fullscreen mode

In addition, the following parameters are provided.

  • url : URL of GROWI. The default is http://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();
Enter fullscreen mode Exit fullscreen mode

The page body is retrieved using the contents method.

const contents = await page.contents();
Enter fullscreen mode Exit fullscreen mode

Get child pages

Use the children method to retrieve child pages. This is an array of Page.

const children = await page.children();
Enter fullscreen mode Exit fullscreen mode

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();
Enter fullscreen mode Exit fullscreen mode

Create a new page

To create a new page, use the create method.

const newPage = await growi.create({name: 'new page'});
Enter fullscreen mode Exit fullscreen mode

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 });
Enter fullscreen mode Exit fullscreen mode

Remove a page

Use the remove method to remove a page.

await page.remove();
Enter fullscreen mode Exit fullscreen mode

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)