Skip to main content

Express Zod API

A TypeScript framework to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.

Key Features

Express Zod API integrates Express.js, Zod validation, and TypeScript to provide a complete framework for building robust APIs.

Quick Example

Here’s how simple it is to create a type-safe endpoint:
import { defaultEndpointsFactory } from "express-zod-api";
import { z } from "zod";

const helloEndpoint = defaultEndpointsFactory.build({
  method: "get",
  input: z.object({
    name: z.string().optional(),
  }),
  output: z.object({
    greetings: z.string(),
  }),
  handler: async ({ input: { name } }) => {
    return { greetings: `Hello, ${name || "World"}!` };
  },
});

Why Express Zod API?

TypeScript First

Built with TypeScript for complete type safety throughout your API

Express Compatible

Built on Express v5 with full compatibility with the Express ecosystem

Zero Boilerplate

Focus on business logic while the framework handles validation and errors

Flexible Routing

Support for nested routes, path parameters, and method-based routing

Production Ready

Built-in HTTPS, compression, CORS, and production mode optimizations

Developer Friendly

Clear error messages, comprehensive testing utilities, and detailed docs

Get Started

1

Install the framework

Install Express Zod API and its peer dependencies
pnpm add express-zod-api express zod http-errors
pnpm add -D @types/express @types/node @types/http-errors
2

Create your first endpoint

Define input/output schemas and handler logic
import { defaultEndpointsFactory, createConfig } from "express-zod-api";
import { z } from "zod";

const endpoint = defaultEndpointsFactory.build({
  input: z.object({ name: z.string() }),
  output: z.object({ greeting: z.string() }),
  handler: async ({ input }) => ({ greeting: `Hello ${input.name}` }),
});
3

Start your server

Configure and launch your API server
import { createServer, Routing } from "express-zod-api";

const routing: Routing = {
  v1: { hello: endpoint },
};

createServer(createConfig({ http: { listen: 8090 } }), routing);

Learn More