A TypeScript client that wraps the Payload REST API and infers types from the generated Payload config types. It exposes typed methods for collections, globals, auth operations and the access endpoint, and supports custom endpoints declared with input and output types. Version 3 targets Payload 3, while older versions serve Payload 2.
A typesafe rest api client for the payload cms.
Installation
npm i payload-rest-client49
Stars
6
Forks
3
Open Issues
1 years ago
Last Updated
1.0k
Weekly Downloads
v3.0.5
npm Version
56.3 KB
Unpacked Size
0
Dependencies
490 since Sep 6
| Date | Stars |
|---|---|
| Dec 5, 2026 | 49 |
| Dec 4, 2026 | 49 |
| Dec 3, 2026 | 49 |
| Dec 2, 2026 | 49 |
| Dec 1, 2026 | 49 |
| Nov 30, 2026 | 49 |
| Nov 29, 2026 | 49 |
| Nov 28, 2026 | 49 |
| Nov 27, 2026 | 49 |
| Nov 26, 2026 | 49 |
| Nov 25, 2026 | 49 |
| Nov 24, 2026 | 49 |
| Nov 23, 2026 | 49 |
| Nov 22, 2026 | 49 |
| Nov 21, 2026 | 49 |
| Nov 20, 2026 | 49 |
| Nov 19, 2026 | 49 |
| Nov 18, 2026 | 49 |
| Nov 17, 2026 | 49 |
| Nov 16, 2026 | 49 |
| Nov 15, 2026 | 49 |
| Nov 14, 2026 | 49 |
| Nov 13, 2026 | 49 |
| Nov 12, 2026 | 49 |
| Nov 11, 2026 | 49 |
| Nov 10, 2026 | 49 |
| Nov 9, 2026 | 49 |
| Nov 8, 2026 | 49 |
| Nov 7, 2026 | 49 |
| Nov 6, 2026 | 49 |
| Nov 5, 2026 | 49 |
| Nov 4, 2026 | 49 |
| Nov 3, 2026 | 49 |
| Nov 2, 2026 | 49 |
| Nov 1, 2026 | 49 |
| Oct 31, 2026 | 49 |
| Oct 30, 2026 | 49 |
| Oct 29, 2026 | 49 |
| Oct 28, 2026 | 49 |
| Oct 27, 2026 | 49 |
| Oct 26, 2026 | 49 |
| Oct 25, 2026 | 49 |
| Oct 24, 2026 | 49 |
| Oct 23, 2026 | 49 |
| Oct 22, 2026 | 49 |
| Oct 21, 2026 | 49 |
| Oct 20, 2026 | 49 |
| Oct 19, 2026 | 49 |
| Oct 18, 2026 | 49 |
| Oct 17, 2026 | 49 |
| Oct 16, 2026 | 49 |
| Oct 15, 2026 | 49 |
| Oct 14, 2026 | 49 |
| Oct 13, 2026 | 49 |
| Oct 12, 2026 | 49 |
| Oct 11, 2026 | 49 |
| Oct 10, 2026 | 49 |
| Oct 9, 2026 | 49 |
| Oct 8, 2026 | 49 |
| Oct 7, 2026 | 49 |
| Oct 6, 2026 | 49 |
| Oct 5, 2026 | 49 |
| Oct 4, 2026 | 49 |
| Oct 3, 2026 | 49 |
| Oct 2, 2026 | 49 |
| Oct 1, 2026 | 49 |
| Sep 30, 2026 | 49 |
| Sep 29, 2026 | 49 |
| Sep 28, 2026 | 49 |
| Sep 27, 2026 | 49 |
| Sep 26, 2026 | 49 |
| Sep 25, 2026 | 49 |
| Sep 24, 2026 | 49 |
| Sep 23, 2026 | 49 |
| Sep 22, 2026 | 49 |
| Sep 21, 2026 | 49 |
| Sep 20, 2026 | 49 |
| Sep 19, 2026 | 49 |
| Sep 18, 2026 | 49 |
| Sep 17, 2026 | 49 |
| Sep 16, 2026 | 49 |
| Sep 15, 2026 | 49 |
| Sep 14, 2026 | 49 |
| Sep 13, 2026 | 49 |
| Sep 12, 2026 | 49 |
| Sep 11, 2026 | 49 |
| Sep 10, 2026 | 49 |
| Sep 9, 2026 | 49 |
| Sep 8, 2026 | 49 |
| Sep 7, 2026 | 49 |
| Sep 6, 2026 | 49 |
1.1K+601 since Sep 6
| Date | Weekly downloads |
|---|---|
| Dec 5, 2026 | 1,076 |
| Dec 4, 2026 | 1,124 |
| Dec 3, 2026 | 1,081 |
| Dec 2, 2026 | 1,062 |
| Dec 1, 2026 | 1,016 |
| Nov 30, 2026 | 895 |
| Nov 29, 2026 | 925 |
| Nov 28, 2026 | 789 |
| Nov 27, 2026 | 763 |
| Nov 26, 2026 | 1,001 |
| Nov 25, 2026 | 1,184 |
| Nov 24, 2026 | 1,368 |
| Nov 23, 2026 | 1,575 |
| Nov 22, 2026 | 1,478 |
| Nov 21, 2026 | 1,564 |
| Nov 20, 2026 | 1,466 |
| Nov 19, 2026 | 1,217 |
| Nov 18, 2026 | 1,146 |
| Nov 17, 2026 | 866 |
| Nov 16, 2026 | 773 |
| Nov 15, 2026 | 746 |
| Nov 14, 2026 | 633 |
| Nov 13, 2026 | 654 |
| Nov 12, 2026 | 643 |
| Nov 11, 2026 | 542 |
| Nov 10, 2026 | 570 |
| Nov 9, 2026 | 468 |
| Nov 8, 2026 | 393 |
| Nov 7, 2026 | 379 |
| Nov 6, 2026 | 338 |
| Nov 5, 2026 | 309 |
| Nov 4, 2026 | 300 |
| Nov 3, 2026 | 260 |
| Nov 2, 2026 | 311 |
| Nov 1, 2026 | 507 |
| Oct 31, 2026 | 530 |
| Oct 30, 2026 | 515 |
| Oct 29, 2026 | 450 |
| Oct 28, 2026 | 403 |
| Oct 27, 2026 | 405 |
| Oct 26, 2026 | 355 |
| Oct 25, 2026 | 138 |
| Oct 24, 2026 | 121 |
| Oct 23, 2026 | 91 |
| Oct 22, 2026 | 146 |
| Oct 21, 2026 | 233 |
| Oct 20, 2026 | 255 |
| Oct 19, 2026 | 268 |
| Oct 18, 2026 | 382 |
| Oct 17, 2026 | 386 |
| Oct 16, 2026 | 410 |
| Oct 15, 2026 | 405 |
| Oct 14, 2026 | 404 |
| Oct 13, 2026 | 424 |
| Oct 12, 2026 | 427 |
| Oct 11, 2026 | 304 |
| Oct 10, 2026 | 289 |
| Oct 9, 2026 | 307 |
| Oct 8, 2026 | 787 |
| Oct 7, 2026 | 782 |
| Oct 6, 2026 | 741 |
| Oct 5, 2026 | 715 |
| Oct 4, 2026 | 882 |
| Oct 3, 2026 | 893 |
| Oct 2, 2026 | 1,056 |
| Oct 1, 2026 | 562 |
| Sep 30, 2026 | 519 |
| Sep 29, 2026 | 558 |
| Sep 28, 2026 | 583 |
| Sep 27, 2026 | 423 |
| Sep 26, 2026 | 409 |
| Sep 25, 2026 | 254 |
| Sep 24, 2026 | 398 |
| Sep 23, 2026 | 405 |
| Sep 22, 2026 | 387 |
| Sep 21, 2026 | 391 |
| Sep 20, 2026 | 382 |
| Sep 19, 2026 | 408 |
| Sep 18, 2026 | 487 |
| Sep 17, 2026 | 351 |
| Sep 16, 2026 | 347 |
| Sep 15, 2026 | 365 |
| Sep 14, 2026 | 357 |
| Sep 13, 2026 | 428 |
| Sep 12, 2026 | 441 |
| Sep 11, 2026 | 377 |
| Sep 10, 2026 | 439 |
| Sep 9, 2026 | 500 |
| Sep 8, 2026 | 475 |
| Sep 7, 2026 | 528 |
| Sep 6, 2026 | 475 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/704946675-root)<a href="https://payloaddirectory.dev/plugins/704946675-root"><img src="https://payloaddirectory.dev/badge/704946675-root.svg" alt="Payload Directory"></a>README
# payload-rest-client
A typesafe rest api client for the [payload cms](https://payloadcms.com).
## Quick Start
1. Assume you have a users (auth enabled) and a posts collection with following fields:
```ts
interface User {
id: string;
email: string;
name: string;
password: string;
createdAt: string;
updatedAt: string;
}
interface Post {
id: string;
title: string;
content: string;
createdAt: string;
updatedAt: string;
}
```
2. Create the client:# payload-rest-client
A typesafe rest api client for the [payload cms](https://payloadcms.com).
## Quick Start
1. Assume you have a users (auth enabled) and a posts collection with following fields:
```ts
interface User {
id: string;
email: string;
name: string;
password: string;
createdAt: string;
updatedAt: string;
}
interface Post {
id: string;
title: string;
content: string;
createdAt: string;
updatedAt: string;
}
```
2. Create the client:
```ts
import { createClient } from "payload-rest-client";
import { Config } from "./payload-types"; // auto generated types from payload
type Locales = "de" | "en";
const client = createClient<Config, Locales>({
apiUrl: "http://localhost:4000/api",
});
```
3. Now you can use all available queries for all collections and globals in a typesafe way:
```ts
// if you wan't to use protected routes, use login api...
const loginResponse = await client.collections.users.login({
email: process.env.PAYLOAD_API_EMAIL,
password: process.env.PAYLOAD_API_PASSWORD,
});
// ...and create another client with authorization header
const protectedClient = createClient<Config, Locales>({
apiUrl: "http://localhost:4000/api",
headers: {
"Authorization": `Bearer ${loginResponse.token}`,
},
});
const posts = await protectedClient.collections.posts.find({
sort: "title", // only top level keys (optionally prefixed with "-") of Post allowed
locale: "de", // only defined locales allowed
limit: 10,
page: 2,
});
console.log(posts); // type of posts is FindResult<Post>
```
## Custom Endpoints
1. Define input and output types for alle custom endpoints:
```ts
import { CustomEndpoint } from "payload-rest-client";
/**
* shape of generic CustomEndpoint type
*
* type Input = {
* params?: Record<string, string>;
* query?: Record<string, any>;
* body?: any;
* };
*
* type Output = any;
*
* type CustomEndpoint<Input, Output>;
*/
type CustomEndpoints = {
greet: CustomEndpoint<{
params: { name: string };
query: { locale: Locales };
}, string>,
};
```
2. Add it to `createClient` function:
```diff
-const client = createClient<Config, Locales>({
- apiUrl: "http://localhost:4000/api",
-});
+const client = createClient<Config, Locales, CustomEndpoints>({
+ apiUrl: "http://localhost:4000/api",
+ customEndpoints: {
+ greet: { method: "GET", path: params => `hello/${params.name}` },
+ },
+});
```
3. Call custom endpoints like this:
```ts
const greeting = await client.custom.greet({
params: { name: "John Doe" },
query: { locale: "en" },
});
```
## API
[Full documentation of the rest api](https://payloadcms.com/docs/rest-api/overview)
### Client options
- apiUrl: string;
- cache?: RequestCache;
- headers?: HeadersInit;
- debug?: boolean;
- getAdditionalFetchOptions?: (params: GetAdditionalFetchOptionsParams) => any;
- customFetchFn? (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
- customEndpoints?: Record<String, CustomEndpointFactory>;
### Collections
- find: (params?: FindParams<T, LOCALES>) => Promise<FindResult<T>>;
- findById: (params: FindByIdParams<LOCALES>) => Promise<T>;
- count: (params: CountParams<T>) => Promise<CountResult>;
- create: (params: CreateParams<T, LOCALES>) => Promise<CreateResult<T>>;
- createDraft: (params: CreateDraftParams<T, LOCALES>) => Promise<CreateDraftResult<T>>;
- update: (params: UpdateParams<T, LOCALES>) => Promise<UpdateResult<T>>;
- updateById: (params: UpdateByIdParams<T, LOCALES>) => Promise<UpdateByIdResult<T>>;
- delete: (params?: DeleteParams<T, LOCALES>) => Promise<DeleteResult<T>>;
- deleteById: (params: DeleteByIdParams<LOCALES>) => Promise<T>;
### Collections with auth enabled (additional to above)
- login: (params: LoginParams) => Promise<LoginResult<T>>;
- logout: (params: LogoutParams) => Promise<LogoutResult>;
- unlock: (params: UnlockParams) => Promise<UnlockResult>;
- refresh-token: (params: RefreshTokenParams) => Promise<RefreshTokenResult>;
- me: (params: MeParams) => Promise<MeResult<T>>;
- forgot-password: (params: ForgotPasswordParams) => Promise<ForgotPasswordResult>;
- reset-password: (params: ResetPasswordParams) => Promise<ResetPasswordResult<T>>;
### Globals
- get: (params?: BaseParams<LOCALES>) => Promise<T>;
- update: (params: UpdateGlobalParams<T, LOCALES>) => Promise<T>;
### Others
- access: () => Promise<AccessResult>;
## Changelog
### v 3.0.5
- Infer id params (`string` or `number`) from type.
### v 3.0.4
- Added custom endpoints
### v 3.0.3
- Added option to use custom fetch function
### v 3.0.2
- Export error types
- Added access api
### v 3.0.1
- Better type inference for joins
### v 3.0.0
- Payload 3 (for Payload 2 use older versions)
- Added `select`, `populate` and `join` params
- Added `count` api
payload oapi
Generate an OpenAPI spec from your Payload config with optional documentation UIs
7631.1k/wk125v3
fields select
Select specific fields in Local API and REST API responses, similar to GraphQL
4839/wk335v3
payload operations
Typed custom RPC operations for Payload with shared Zod contracts, server endpoints and type-safe clients
77208/wk3v3
payload plugin openapi
Generate an OpenAPI 3.0, 3.1 or 3.2 spec from your Payload config and serve it with Scalar or Swagger UI
701.4k/wk18v4
payload schema export
Serve a JSON description of your Payload collections, fields, relations, locales and REST routes
6010/wk0v3
openapi
Generate OpenAPI 3 documents from your Payload config, including collection, global and custom endpoints
521.4k/wk143v1