{"repo":"htunnicliff/next-api-middleware","free":true,"listed":false,"github":"https://github.com/htunnicliff/next-api-middleware","clone":"git clone https://github.com/htunnicliff/next-api-middleware.git","description":"Middleware for API routes using the Next.js Pages Router","language":"TypeScript","stars":274,"topics":["nextjs","nodejs","middleware","api-middleware","middleware-functions","api-routes","next","react"],"license":"MIT","category":"api-integrations-sdks","readme_excerpt":"Next.js API Middleware Introduction ⚠️ This library was written to support API routes that use the Next.js Pages Router. It has not been tested with the App Router. Next.js API routes are a ridiculously fun and simple way to add backend functionality to a React app. However, when it comes time to add middleware, there is no easy way to implement it. The official Next.js docs recommend writing functions inside your API route handler. This is a huge step backward compared to the clean APIs provided by Express.js or Koa.js. This library attempts to provide minimal, clean, composable middleware patterns that are both productive and pleasant to use. Table of Contents - Quick Start - How It Works - APIs - label - use - Usage Guide - Advanced - Middleware Factories - Middleware Signature - Alternatives Quick Start How It Works My mental model for how this library handles middleware functions is that of a \"winding and unwinding stack.\" Let's imagine you've used label to add two middleware functions to an API route. When a request comes in, this is a rough impression of how that request makes its way through all middleware functions, the API route handler itself, and then back up through the middleware. While this is a crummy ASCII diagram, I think it gives the right impression. The request winds its way though each middleware function in succession, hits the API route handler, and then proceeds to \"unwind\" its way through the stack. Every middleware function has the opportunity to go","default_branch":null,"files":null,"tree":[],"storefront":"/r/htunnicliff","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/htunnicliff/next-api-middleware/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}