It helps you to use microCMS from JavaScript and Node.js applications.
Install npm package.
$ npm install microcms-js-sdk
or
$ yarn add microcms-js-sdk
CDN support.
<script src="https://unpkg.com/microcms-js-sdk@latest/dist/umd/microcms-js-sdk.js"></script>
First, create a client.
const { createClient } = require("microcms-js-sdk"); // CommonJS
import { createClient } from 'microcms-js-sdk'; //ES6
// Initialize Client SDK.
const client = createClient({
serviceDomain: "YOUR_DOMAIN",
apiKey: "YOUR_API_KEY",
globalDraftKey: "YOUR_GLOBAL_DRAFT_KEY", // If need
});
When using with a browser.
<script>
const { createClient } = microcms;
// Initialize Client SDK.
const client = createClient({
serviceDomain: "YOUR_DOMAIN",
apiKey: "YOUR_API_KEY",
globalDraftKey: "YOUR_GLOBAL_DRAFT_KEY", // If need
});
</script>
After, How to use it below.
client
.get({
endpoint: 'endpoint',
queries: { limit: 20, filters: 'createdAt[greater_than]2021' },
})
.then((res) => console.log(res))
.catch((err) => console.log(err));
client
.get({
endpoint: 'endpoint',
contentId: 'contentId',
queries: { fields: 'title,publishedAt' },
})
.then((res) => console.log(res))
.catch((err) => console.log(err));
Apache-2.0