Skip to content

Consuming API

Learn how to integrate Stelo CMS content into your frontend applications using the tRPC client.

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`,
}),
],
};
},
});
// Get a specific page
const page = await trpc.pages.getBySlug.query({
slug: 'about-us',
locale: 'en'
});
// Get all published pages
const pages = await trpc.pages.getPublished.query({
locale: 'en'
});
// Get services
const services = await trpc.collections.getByType.query({
type: 'SERVICE',
locale: 'en',
published: true
});
// Get site-wide settings
const header = await trpc.globals.getByKey.query({
key: 'header'
});

Combine API calls with Next.js static generation for optimal performance.

This section will be expanded with detailed integration examples.