@content-island/api-client
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

@content-island/api-client

Installation

npm install @content-island/api-client

Usage

import { createClient } from '@content-island/api-client';

const client = createClient({ accessToken: <your-token>});

const project = client.getProject(); // Retrieve the project by access token

const contents = client.getContentList(); // Retrieve the list of contents in the project

const postContents = client.getContentList({ contentType: 'post'}); // Retrieve the list of contents in the project filtered by content type, for example 'post'

const content = client.getContent('content-id'); // Retrieve a content by id

const content = client.getContent('content-id', { contentType: 'post'}); // Retrieve a content by id filtered by content type, for example 'post'

API

createClient(options): endpoints

Creates a client instance.

options

name type required description
accessToken string true The access token of the project
domain string false The domain of the project. Default: api.contentisland.net
apiVersion string false The version of the API. Default: 1.0

endpoints

getProject()

Retrieves the project by access token.

getContentList(queryParams)

Retrieves the list of contents in the project.

getContent(contentId, queryParams)

Retrieves a content by id.

queryParams

The query parameters to filter the list of contents.

param Description
contentType The content type to filter the list of contents. For example: post

mapContentToModel(content)

Maps a list of fields to a model.

const content: Content = {
  id: '1',
  contentType: { id: '10', name: 'post' },
  lastUpdate: '2023-10-20T00:00:00.000Z',
  fields: [
    {
      id: '100',
      name: 'title',
      value: 'My title',
      type: 'short-text',
      isArray: false,
      language: 'en',
    },
    {
      id: '200',
      name: 'body',
      value: '# My body',
      type: 'long-text',
      isArray: false,
      language: 'en',
    },
    {
      id: '300',
      name: 'order',
      value: 1,
      type: 'number',
      isArray: false,
      language: 'en',
    },
  ],
};

interface Post {
  id: string;
  title: string;
  body: string;
  order: number;
}

const post = mapContentToModel<Post>(fields);

console.log(post); // { id: '1', title: 'My title', body: '# My body', order: 1 }

Readme

Keywords

none

Package Sidebar

Install

npm i @content-island/api-client

Weekly Downloads

21

Version

0.4.0

License

MIT

Unpacked Size

8.73 kB

Total Files

14

Last publish

Collaborators

  • content-island