Skip to content

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
endpointendpoint.query() and endpoint.mutation(). Each returns a NestJS controller class.
decoratedPairs a NestJS decorator with a TypeScript type, for inject and injectOnRequest.
schemaAttaches an OpenAPI description to a Zod schema.
zZod, re-exported.
EndpointResponseWhat response(status, body) returns, and what invoke() resolves to for an endpoint with several statuses.

Routers ​

Export
NestjsEndpointsNestjsEndpoints.forRoot() sets the library up in the app's root module, and makes its root router.
EndpointRouterModuleEndpointRouterModule.create() makes any other router.

Clients ​

Export
setupCodegenGenerates the axios and React Query clients.

Exceptions ​

Export
ZodValidationExceptionThrown when input, query or params fails its schema. A BadRequestException, answered 400.
ZodSerializationExceptionThrown when a return value fails output. An InternalServerErrorException, answered 500.

Both have a getZodError() method, which returns the ZodError.

Types ​

Export
NestjsEndpointsOptionsThe options of NestjsEndpoints.forRoot().
EndpointRouterWhat NestjsEndpoints.forRoot() and EndpointRouterModule.create() return.
EndpointBuilder, EndpointBuildersThe types of endpoint.query and of endpoint itself.

OpenAPI helpers ​

Export
ApiQueries, ApiParamsDecorators 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:

DeprecatedUse
EndpointsRouterModuleEndpointRouterModule
EndpointsRouterModule.register()EndpointRouterModule.create()
injectMethod, injectAtRequestinjectOnRequest

Released under the MIT License.