next-api-handler
TypeScript icon, indicating that this package has built-in type declarations

0.4.10 • Public • Published

next-api-handler


install size CircleCI codecov next-api-handler Known Vulnerabilities

Lightweight and Portable Next.js API builder

Building RESTful API routes in Next.js with middleware support, predictable error handling and type-safe interfaces for client-server communication.

Visit https://next-api-handler.vercel.app to view the full documentation.

Getting Started

TL;DR

npm install next-api-handler # or yarn, pnpm
// in /pages/api/users.ts
import { RouterBuilder, ForbiddenException } from 'next-api-handler';
import { createUser, type User } from '@/services/user';

const router = new RouterBuilder();

router
  .get<string>(() => 'Hello World!')
  .post<User>(async (req) => createUser(req.body))
  .delete(() => {
    throw new ForbiddenException();
  });

export default router.build();

License

MIT

Package Sidebar

Install

npm i next-api-handler

Weekly Downloads

952

Version

0.4.10

License

MIT

Unpacked Size

87.6 kB

Total Files

72

Last publish

Collaborators

  • howard86