nestjs-endpoints
v3.2.0
Published
Write each NestJS endpoint as one file: its folder gives it a URL, its routers give it path parameters, providers and guards, and its Zod schemas give it validation and a typed axios or React Query client.
Maintainers
Readme
nestjs-endpoints
End-to-end type safety, built on NestJS controllers.
Write each endpoint as one file, with Zod schemas for its request and response and a handler. nestjs-endpoints serves it at a route that comes from where the file sits, hands it the path parameters, providers and guards the routers of its folders declare, validates what goes in and out, and generates a typed axios or React Query client from the same schemas.
Documentation: nestjs-endpoints.dev
Features
- NestJS controllers underneath. Modules, providers, guards, interceptors and the Express,
Fastify and
node:httpadapters work as they do in any Nest app. - File-based routing. An endpoint's URL is its path in the folder, or a
pathyou give it. - Validation and types from one schema. Bodies, search parameters and path parameters are parsed before the handler runs, and a response that doesn't match its schema doesn't compile.
- Generated clients. A typed axios client or React Query hooks, nested by the routers' namespaces.
- Routers that share down the tree. A
router.tsdeclares a folder's path parameters, providers, guards, middleware and interceptors once, for every endpoint under it and every router nested in it. - State and lifecycle hooks. An endpoint or a router keeps its own properties and methods, and runs NestJS's lifecycle hooks.
- Built for coding agents. An agent rules file and a skill that point an agent at the docs
shipped inside the package, and a
/nestjs-endpoints-refactorskill that reworks an API to the recommended architecture.
Install
npm install nestjs-endpoints zodRequires Node.js 24.22, NestJS 12, TypeScript 6 and Zod 4.1 or newer, in an ESM project.
Quick start
// src/app.module.ts
import { Module } from '@nestjs/common';
import { NestjsEndpoints } from 'nestjs-endpoints';
@Module({
imports: [NestjsEndpoints.forRoot({ router: { rootDirectory: './endpoints' } })],
})
export class AppModule {}// src/endpoints/greet.endpoint.ts → POST /greet
import { endpoint, z } from 'nestjs-endpoints';
export default endpoint.query({
input: z.object({ name: z.string() }),
output: z.string(),
handler: ({ input }) => `Hello, ${input.name}!`,
});// with the generated clients
const greeting = await client.greet({ body: { name: 'Satie' } });
const { data } = client.useGreet({ body: { name: 'Satie' } });Documentation
- Getting started
- Recommended architecture
- Writing an endpoint
- File-based routing
- Generating clients
- Testing
- Built for agents
A complete example, an API with a React front end, is in
examples/file-based-routing.
For coding agents, the docs are indexed at
nestjs-endpoints.dev/llms.txt, and ship inside the
package at node_modules/nestjs-endpoints/docs/llms.txt.
License
MIT
