A typesafe REST API client for Payload CMS (current stable version 3.0.5, actively maintained). It provides a fully typed interface for all Payload CMS REST endpoints, including collections, globals, and custom endpoints. The client leverages TypeScript generics to enforce correct parameters, query options, and response types based on your Payload config. Key differentiators: first-class locale support, built-in auth methods (login, logout, refresh, unlock), and a type-safe custom endpoint system. Unlike generic fetch wrappers, it automatically types collection methods (find, create, update, delete) with your actual content types. Requires Payload CMS v2+.
npm install payload-rest-clientNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to create a typed client, authenticate, and fetch a paginated list of posts with locale and sorting.
Ensure the Config type you pass to createClient matches the generated 'payload-types.ts' from Payload CMS. Use the exact type from your config export.
Define locale type as e.g. 'en' | 'de' instead of string when creating client.
Replace 'import { payloadRestClient } from "payload-rest-client"' with 'import { createClient } from "payload-rest-client"'.Always provide both method and path for each custom endpoint. Path can be a string or a function returning a string.
Run 'npm install payload-rest-client' and ensure your project uses ESM ("type": "module" in package.json) or a bundler that supports ESM.Ensure your Config type includes the collections object with expected keys (e.g., 'posts'). Check that createClient receives correct generic parameters.
Verify Payload config has auth enabled on users (auth: true). Check that your Config type matches the actual collection schema.