/spearly-sdk-js

Primary LanguageTypeScriptApache License 2.0Apache-2.0

@spearly/sdk-js

Spec Test

It is a Development Kit that makes it easy to use Spearly CMS from JavaScript or NodeJS in API mode.

Getting Started

Install

// npm
$ npm install -S @spearly/sdk-js

// yarn
$ yarn add @spearly/sdk-js

Usage

Setup

import { SpearlyApiClient } from '@spearly/sdk-js'

const apiClient = new SpearlyApiClient(SPEARLY_DOMAIN, API_KEY)

Get Content Lists

async function() {
  // basic
  const contents =  await apiClient.getList(CONTENT_TYPE_ID)

  // when using some options
  const filteredContents =  await apiClient.getList(CONTENT_TYPE_ID, { limit: 10, offset: 20 })
}

Get Content

async function() {
  const content = await apiClient.getContent(CONTENT_ID)
}

Get Form

async function() {
  const form = await apiClient.getFormLatest(FORM_ID)
}

Submit Form

async function() {
  const submit = await apiClient.postFormAnswers(FORM_VERSION_ID, { ...YOUR_FORM_FIRLD_ANSWERS, _spearly_gotcha: '' })
}

Support TypeScript

Type definitions are also included, so there is no need to add anything else.

  • GetParams : This is options that can be set when retrieving the ContentList.
  • List : The type of the content list returned by the API.
  • Content : The type of content returned by the API.
  • Form : The type of form returned by the API.