Exports
Everything is exported from the package's root:
ts
import {
endpoint,
decorated,
schema,
z,
NestjsEndpoints,
EndpointRouterModule,
setupCodegen,
EndpointResponse,
ZodValidationException,
ZodSerializationException,
} from 'nestjs-endpoints';Endpoints
| Export | |
|---|---|
endpoint | endpoint.query() and endpoint.mutation(). Each returns a NestJS controller class. |
decorated | Pairs a NestJS decorator with a TypeScript type, for inject and injectOnRequest. |
schema | Attaches an OpenAPI description to a Zod schema. |
z | Zod, re-exported. |
EndpointResponse | What response(status, body) returns, and what invoke() resolves to for an endpoint with several statuses. |
Routers
| Export | |
|---|---|
NestjsEndpoints | NestjsEndpoints.forRoot() sets the library up in the app's root module, and makes its root router. |
EndpointRouterModule | EndpointRouterModule.create() makes any other router. |
Clients
| Export | |
|---|---|
setupCodegen | Generates the axios and React Query clients. |
Exceptions
| Export | |
|---|---|
ZodValidationException | Thrown when input, query or params fails its schema. A BadRequestException, answered 400. |
ZodSerializationException | Thrown when a return value fails output. An InternalServerErrorException, answered 500. |
Both have a getZodError() method, which returns the ZodError.
Types
| Export | |
|---|---|
NestjsEndpointsOptions | The options of NestjsEndpoints.forRoot(). |
EndpointRouter | What NestjsEndpoints.forRoot() and EndpointRouterModule.create() return. |
EndpointBuilder, EndpointBuilders | The types of endpoint.query and of endpoint itself. |
OpenAPI helpers
| Export | |
|---|---|
ApiQueries, ApiParams | Decorators that document a Zod object schema as query or path parameters. Endpoints apply them for you, so they are rarely needed directly. Without @nestjs/swagger installed they do nothing. |
Deprecated names
These still work. Use the current name in new code:
| Deprecated | Use |
|---|---|
EndpointsRouterModule | EndpointRouterModule |
EndpointsRouterModule.register() | EndpointRouterModule.create() |
injectMethod, injectAtRequest | injectOnRequest |