0.3.3 • Published 2 years ago

microcms-filter-query v0.3.3

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

microcms-filter-query

microcmsのリスト API の get クエリ、filterの条件文の作成補助ツール

Installed

npm i microcms-filter-query
# or
yarn add microcms-filter-query

Usage

basic usage.

const { MicroCMSFilterQuery } = require('microcms-filter-query') // CommonJS
import { MicroCMSFilterQuery } from 'microcms-filter-query' //ES6

// gender[equals]female
const filterQuery = new MicroCMSFilterQuery()
  .equals('gender', 'female')
  .$execute()

// Get request to microcms
axios.get('https://{SERVICE_ID}.microcms.io/api/v1/{END_POINT}', {
  headers: {
    'X-MICROCMS-API-KEY': `{API_KEY}`,
  },
  params: {
    filters: filterQuery,
  },
})

usage for TypeScript.

import { MicroCMSFilterQuery } from 'microcms-filter-query'

type Avatar = {
  name: string
  gender: 'female' | 'male' | 'other'
}

// gender[equals]female
const filterQuery = new MicroCMSFilterQuery<Avatar & MicroCMSListContent>()
  .equals('gender', 'female') // argument is type safe
  .$execute()

// Get request to microcms
axios.get<MicroCMSListResponse<Avatar>>(
  'https://{SERVICE_ID}.microcms.io/api/v1/{END_POINT}',
  {
    headers: {
      'X-MICROCMS-API-KEY': `{API_KEY}`,
    },
    params: {
      filters: filterQuery,
    },
  }
)
0.3.3

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago