@lapage/content-api
v0.1.4
Published
Reusable client for LaPage ContentAPI-backed content, products, authors, media, and web data.
Readme
@lapage/content-api
Reusable TypeScript client for the LaPage ContentAPI.
Install
npm install @lapage/content-apiUsage
Authenticated create and update mutations are always published atomically through Strapi Content Manager's publish actions. Callers do not need a separate publish request.
import { ContentApi } from '@lapage/content-api';
const contentApi = new ContentApi({
baseUrl: process.env.CONTENT_API_BASE_URL,
projectId: process.env.CONTENT_API_PROJECT_ID,
user: process.env.CONTENT_API_USER,
password: process.env.CONTENT_API_PASSWORD,
});
const posts = await contentApi.getPosts({
postTypes: ['blog'],
fields: ['title', 'slug'],
});
await contentApi.createPost({
title: 'Metadata-aware post',
metadata: {
title: 'Search and social title',
description: 'Search and social description',
keywords: 'content, strapi, lapage',
imageUrl: '/uploads/social-card.jpg',
},
});Generic posts expose localized metadata with title, description,
keywords, and imageUrl. Root-relative metadata image URLs are normalized
against CONTENT_API_BASE_URL on reads.
Environment variables
CONTENT_API_BASE_URL: Base URL of the ContentAPI server. Defaults tohttp://localhost:1337.CONTENT_API_PROJECT_ID: Optional default project id automatically applied to queries and mutations.CONTENT_API_USER: Strapi administrator email used to authenticate write and media operations.CONTENT_API_PASSWORD: Password for the Strapi user used by write and media operations.
Read requests do not require authentication. The first write, edit, delete, media
listing, or upload request logs in through Strapi's admin auth endpoint and caches
the returned JWT. If Strapi rejects a cached JWT with 401, the client logs in
again and retries the request once.
Publish
npm run build
npm publish --access public