Skip to content

Getting Started

This guide walks you through installing strapi-typed-client, registering the Strapi plugin, generating types, and making your first typed API call.

Requirements

  • Strapi v5 (Strapi v4 is not supported)
  • Node.js >= 18

Installation

Install the package in both your Strapi backend and your frontend project:

bash
npm install strapi-typed-client
bash
yarn add strapi-typed-client
bash
pnpm add strapi-typed-client

Register the Strapi Plugin

The package includes a Strapi plugin that exposes your schema via a REST endpoint. Since the strapi field in package.json declares it as a plugin, Strapi auto-discovers it — no manual import or resolve needed.

Enable it in your Strapi project's config/plugins.ts:

ts
// config/plugins.ts
export default {
    'strapi-typed-client': {
        enabled: true,
        config: {
            requireAuth: false, // default: false in dev, true in production
        },
    },
}

After adding the config, restart your Strapi server.

WARNING

When requireAuth is not set, the plugin defaults to requiring auth in production (NODE_ENV === 'production') and not requiring it in development. Set it explicitly if you need a specific behavior.

Plugin Endpoints

Once the plugin is active, two endpoints become available:

EndpointDescription
GET /api/strapi-typed-client/schemaReturns the full content-type schema as JSON + hash
GET /api/strapi-typed-client/schema-hashReturns only the schema hash (used for change detection)

TIP

These endpoints are used by the CLI to fetch your schema. You do not need to call them manually.

Creating an API Token

If you enable requireAuth: true (or deploy to production where it's enabled by default), you need an API token. To create one:

  1. Open the Strapi admin panel.
  2. Go to SettingsGlobal SettingsAPI Tokens.
  3. Click Create new API Token.
  4. Set a Name (e.g., "Types Generator"), choose Token typeRead-only is sufficient for schema fetching.
  5. Click Save and copy the token immediately — it is shown only once.

Pass the token to the CLI:

bash
npx strapi-types generate --url http://localhost:1337 --token YOUR_TOKEN

Or via environment variable:

bash
STRAPI_TOKEN=your-token npx strapi-types generate

See Authentication for more details.

Generate Types

With Strapi running, use the CLI to fetch the schema and generate TypeScript types and a typed client:

bash
npx strapi-types generate --url http://localhost:1337

This generates files directly into the installed package (node_modules/strapi-typed-client/dist) so you can import from strapi-typed-client immediately:

FileDescription
types.d.tsTypeScript interfaces for all content types and components
client.jsA typed StrapiClient class with methods for every collection
index.jsRe-exports everything from types and client

You can change the output directory with the --output flag:

bash
npx strapi-types generate --url http://localhost:1337 --output ./src/strapi

Quick Usage

Once types are generated, create a client and start making typed API calls:

ts
import { StrapiClient } from 'strapi-typed-client'

const strapi = new StrapiClient({
    baseURL: 'http://localhost:1337',
})

// Fully typed — autocomplete for filters, sort, populate
const articles = await strapi.articles.find({
    filters: { title: { $contains: 'hello' } },
    sort: ['createdAt:desc'],
    pagination: { page: 1, pageSize: 10 },
})

console.log(articles.data) // Article[]

INFO

The client uses the global fetch by default. In Next.js, this means you automatically get all of Next.js's fetch optimizations (caching, deduplication, revalidation). See the Next.js integration guide for details.

Next Steps

Released under the MIT License.