Skip to main content

Intro

Overview

Next REST Framework is an open-source, opinionated, lightweight, easy-to-use set of tools to build type-safe, self-documenting APIs with Next.js. Building OpenAPI specification-compliant REST APIs can be cumbersome and slow but Next REST Framework makes this easy with auto-generated OpenAPI documents and docs using TypeScript and object schemas.

Features

Lightweight, type-safe, easy to use

  • Designed to work with TypeScript so that your requests and responses are strongly typed.
  • Object-schema validation with Zod. The object schemas are automatically converted to JSON schema format for the auto-generated OpenAPI specification.
  • Auto-generated and extensible openapi.json spec file from your business logic.
  • Auto-generated Redoc and/or SwaggerUI documentation frontend.
  • Works with Next.js Middleware and other server-side libraries, like NextAuth.js.
  • Supports both Next.js app router and pages router, even at the same time.
  • Fully customizable and compatible with any existing Next.js project.
  • Supports Edge runtime.

Requirements

You also need the following dependencies installed in you Next.js project:

  • Next.js >= v12
  • Optional (needed for validating input): Zod >= v3
  • Optional: TypeScript >= v3
  • Optional (needed when using the CLI commands and using TypeScript): tsx >= v4
  • Optional (needed if working with forms): zod-form-data >= v2

Installation

npm install next-rest-framework