0.4.0 • Published 7 months ago

@content-island/api-client v0.4.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

@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

nametyperequireddescription
accessTokenstringtrueThe access token of the project
domainstringfalseThe domain of the project. Default: api.contentisland.net
apiVersionstringfalseThe 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.

paramDescription
contentTypeThe 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 }
0.4.0

7 months ago

0.3.1

7 months ago

0.3.0

7 months ago

0.2.1

8 months ago

0.2.0

8 months ago

0.1.0

8 months ago