freecms-client
v1.0.0
Published
Powerful, Type-Safe Lightweight SDK for the FreeCMS Delivery API
Downloads
120
Maintainers
Readme
FreeCMS Client SDK
The highly-optimized, type-safe API client for connecting any frontend application to your FreeCMS Delivery API.
Features
- Zero Dependencies: Powered entirely by the native
fetchAPI. Small & fast. - Isomorphic: Works flawlessly on the server (Next.js, Nuxt) and the browser (React, Vue, Vanilla).
- TypeScript First: Includes rich type definitions out of the box.
Installation
npm install freecms-client
# or
yarn add freecms-clientNote: You can npm link or install from this local directory while testing.
Usage
import { CMSClient, CMSEntry } from 'freecms-client';
// 1. Initialize the client
const cms = new CMSClient('your_project_api_key'); // Simply pass your API Key !
// 2. Fetch all entries for a Model
async function fetchArticles() {
const articles = await cms.getEntries('blog-post');
console.log(articles[0].data.title);
}
// 3. Fetch a specific entry by its ID or Slug
async function fetchFeatured() {
const feature = await cms.getEntry('blog-post', 'some-entry-slug');
console.log(feature.data.content);
}Types
The SDK exports CMSClientConfig and CMSEntry<T>.
You can strongly type your records like this:
interface ArticleData {
title: string;
body: string;
isPublished: boolean;
}
const articles = await cms.getEntries<ArticleData>('blog-post');
// articles[0].data.title will be correctly typed as a string!