0.0.8 • Published 4 years ago

microcms-client v0.0.8

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

microCMS-client

This is a microCMS client for javascript and typeScript. The microCMS is made in Japan. Plus, it's very cool. microCMS can be found here.

install

npm

npm install microcms-client

yarn

yarn add microcms-client

How to use

Creating Clients

import { createClient } from 'microcms-client/lib/client';

// create client.
const client = createClient({
  baseUrl: 'https://yourname.microcms.io/api/v1/',
  contentType: 'application/json; charset=utf-8',
  X_API_KEY: 'your_api_key',
});

Getting a single piece of content.

const path = 'contents'

// Accessed  'https://yourname.microcms.io/api/v1/contents/${contentId}'
export const getContent = (contentId: string) => {
  return client.getContent<Content>({ path: path, contentId: contentId });
};

Get a collection of content.

const path = 'contents'

// Accessed  'https://yourname.microcms.io/api/v1/contents/'
export const getContents = () => {
  return client.getContents<Content>({ path: path });
};

When issuing a query conditionally.

const path = 'contents'

// Accessed  'https://yourname.microcms.io/api/v1/contents/filter=tags[contains]${tagContentId}'
export const getContentsByTagsContentId = (tagContentId: string) => {
  // Creating a filter.
  const filters: Filters[] = [
    {
      key: 'tags',
      filterType: 'contains',
      value: tagContentId,
    },
  ];

  const param: GetContentsParams = {
    path,
    filters,
  };

  return client.getContents<Content>(param);
};
0.0.3

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago