Consuming API
Consuming the API
Section titled “Consuming the API”Learn how to integrate Stelo CMS content into your frontend applications using the tRPC client.
tRPC Client Setup
Section titled “tRPC Client Setup”import { createTRPCNext } from '@trpc/next';import { httpBatchLink } from '@trpc/client';import type { AppRouter } from '../../../stelo-cms/src/app/api/trpc/route';
export const trpc = createTRPCNext<AppRouter>({ config() { return { links: [ httpBatchLink({ url: `${process.env.NEXT_PUBLIC_CMS_URL}/api/trpc`, }), ], }; },});Fetching Content
Section titled “Fetching Content”// Get a specific pageconst page = await trpc.pages.getBySlug.query({ slug: 'about-us', locale: 'en'});
// Get all published pagesconst pages = await trpc.pages.getPublished.query({ locale: 'en'});Collections
Section titled “Collections”// Get servicesconst services = await trpc.collections.getByType.query({ type: 'SERVICE', locale: 'en', published: true});Globals
Section titled “Globals”// Get site-wide settingsconst header = await trpc.globals.getByKey.query({ key: 'header'});Static Generation
Section titled “Static Generation”Combine API calls with Next.js static generation for optimal performance.
This section will be expanded with detailed integration examples.