MCPcopy Index your code
hub / github.com/RobinTail/express-zod-api

github.com/RobinTail/express-zod-api @migration-v28.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release migration-v28.0.1 ↗ · + Follow
456 symbols 1,285 edges 161 files 64 documented · 14% updated 1d agoexpress-zod-api-v28.7.5 · 2026-07-03★ 830
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Express Zod API

logo

CI OpenAPI coverage

downloads npm release GitHub Repo stars License

Start your API server with I/O schema validation and custom middlewares in minutes.

  1. Overview
  2. How it works
  3. Quick startFast Track
  4. Basic features
  5. Routing including static file serving
  6. Middlewares
  7. Context
  8. Using native express middlewares
  9. Refinements
  10. Query string parser
  11. Transformations
  12. Top level transformations and mapping
  13. Dealing with dates
  14. Pagination
  15. Cross-Origin Resource Sharing (CORS)
  16. Enabling HTTPS
  17. Enabling compression
  18. Customizing logger
  19. Child logger
  20. Advanced features
  21. Customizing input sources
  22. Headers as input source
  23. Response customization
  24. Empty response
  25. Non-JSON response including file downloads
  26. Error handling
  27. Production mode
  28. HTML Forms (URL encoded)
  29. File uploads
  30. Connect to your own express app
  31. Testing endpoints
  32. Testing middlewares
  33. Integration and Documentation
  34. Zod Plugin
  35. End-to-End Type Safety
  36. Creating documentation
  37. Tagging the endpoints
  38. Deprecated schemas and routes
  39. Customizable brands handling
  40. Special needs
  41. Different responses for different status codes
  42. Array response for migrating legacy APIs
  43. Accepting raw data
  44. Profiling
  45. Graceful shutdown
  46. Subscriptions
  47. Caveats
  48. Excessive properties in endpoint output
  49. Your input to my output

See also Changelog and automated migration.

Overview

I made this framework because of the often repetitive tasks of starting web server APIs with the need to validate input data. It integrates and provides the capabilities of popular web server, logging, validation, and documenting solutions. Therefore, many basic tasks can be achieved faster and easier, in particular:

  • You can describe web server routes as a hierarchical object.
  • You can keep the endpoint's input and output type declarations right next to its handler.
  • All input and output data types are validated, so it ensures you won't have an empty string, null or undefined where you expect a number.
  • Variables within an endpoint handler have types according to the declared schema, so your IDE and TypeScript will provide you with necessary hints to focus on bringing your vision to life.
  • All of your endpoints can respond consistently.
  • The expected endpoint input and response types can be exported to the frontend, giving you end-to-end type safety so you don't get confused about the field names when you implement the client for your API.
  • You can generate your API documentation in OpenAPI 3.1 and JSON Schema compatible format.

Contributors

These people contributed to the improvement of the framework by reporting bugs, making changes, and suggesting ideas:

@pycanis @arlyon @Upsilon-Iridani @NicolasMahe @shadone @squishykid @jakub-msqt @misha-z1nchuk @GreaterTamarack @pepegc @MichaelHindley @zoton2 @ThomasKientz @james10424 @HeikoOsigus @crgeary @williamgcampbell @gmorgen1 @danmichaelo @APTy @LufyCZ @mlms13 @bobgubko @LucWag @HenriJ @JonParton @t1nky @Tomtec331 @rottmann @boarush @shawncarr @uxduck @daniel-white @kotsmile @elee1766 @danclaytondev @huyhoang160593 @sarahssharkey @master-chu @alindsay55661 @john-schmitz @miki725 @dev-m1-macbook @McMerph @niklashigi @maxcohn @VideoSystemsTech @TheWisestOne @lazylace37 @leosuncin @kirdk @johngeorgewright @ssteuteville @foxfirecodes @HardCoreQual @hellovai @Isaac-Leonard @digimuza @glitch452

How it works

Concept

The API operates object schemas for input and output validation. The object being validated is the combination of certain request properties. It is available to the endpoint handler as the input parameter. Middlewares have access to all request properties, they can provide endpoints with ctx (context). The object returned by the endpoint handler is called output. It goes to the ResultHandler which is responsible for transmitting consistent responses containing the output or possible error. Much can be customized to fit your needs.

Dataflow

Technologies

  • Typescript first.
  • Web server — Express.js v5.
  • Schema validation — Zod 4.x;
  • Supports any logger having info(), debug(), error() and warn() methods;
  • Built-in console logger with colorful and pretty inspections by default.
  • Generators:
  • Documentation — OpenAPI 3.1 (former Swagger);
  • Client side types — inspired by zod-to-ts.
  • File uploads — Express-FileUpload (based on Busboy).

Quick start

Installation

Install the framework, its peer dependencies and type assistance packages using your favorite package manager.

# example for pnpm:
pnpm add express-zod-api express zod http-errors
pnpm add -D @types/express @types/node @types/http-errors

Environment preparation

Enable the following compilerOptions in your tsconfig.json to make it work as expected:

{
  "compilerOptions": {
    "strict": true,
    "skipLibCheck": true
  }
}

Set up config

Create a minimal configuration. Find out all configurable options in sources.

import { createConfig } from "express-zod-api";

const config = createConfig({
  http: { listen: 8090 }, // port, UNIX socket or Net::ListenOptions
  cors: false, // decide whether to enable CORS
});

Create your first endpoint

Use the default factory to make an endpoint that responds with "Hello, World" or "Hello, {name}" depending on inputs. Learn how to make factories for custom response and by adding middlewares.

```ts import { defaultEndpoi

Extension points exported contracts — how you extend this code

GetV1UserRetrievePositiveResponseVariants (Interface)
get /v1/user/retrieve
example/example.client.ts
CommonPaginationConfig (Interface)
@desc Common pagination config: shared by offset and cursor styles.
express-zod-api/src/paginated-schema.ts
LoggerOverrides (Interface)
(no doc)
example/config.ts
TagOverrides (Interface)
(no doc)
issue952-test/tags.ts
GlobalMeta (Interface)
(no doc)
zod-plugin/src/augmentation.ts
Queries (Interface)
(no doc)
migration/index.ts
GetV1UserRetrieveNegativeResponseVariants (Interface)
get /v1/user/retrieve
example/example.client.ts
OffsetPaginatedConfig (Interface)
* @desc Configuration for offset-based pagination (limit and offset). * @example { style: "offset", itemSchema, maxLimi
express-zod-api/src/paginated-schema.ts

Core symbols most depended-on inside this repo

build
called by 121
express-zod-api/src/endpoints-factory.ts
makeLoggerMock
called by 43
express-zod-api/src/testing.ts
makeRequestMock
called by 34
express-zod-api/src/testing.ts
makeResponseMock
called by 28
express-zod-api/src/testing.ts
addMiddleware
called by 28
express-zod-api/src/endpoints-factory.ts
propOf
called by 27
express-zod-api/src/typescript-api.ts
zodToTs
called by 26
express-zod-api/src/zts.ts
processContainers
called by 26
express-zod-api/src/logical-container.ts

Shape

Function 222
Interface 97
Method 83
Class 50
Enum 4

Languages

TypeScript100%

Modules by API surface

example/example.client.ts53 symbols
express-zod-api/src/documentation-helpers.ts39 symbols
express-zod-api/src/endpoint.ts24 symbols
express-zod-api/src/errors.ts23 symbols
express-zod-api/src/zts.ts21 symbols
express-zod-api/src/builtin-logger.ts15 symbols
express-zod-api/src/common-helpers.ts14 symbols
express-zod-api/src/server-helpers.ts12 symbols
express-zod-api/src/security.ts11 symbols
express-zod-api/src/middleware.ts11 symbols
express-zod-api/src/integration.ts11 symbols
express-zod-api/src/endpoints-factory.ts10 symbols

Datastores touched

(mongodb)Database · 1 repos

For agents

$ claude mcp add express-zod-api \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page