Back to Next Js

API routes with middleware

examples/api-routes-middleware/README.md

16.2.51.2 KB
Original Source

API routes with middleware

Next.js ships with API routes, which provide an easy solution to build your own API. This example shows how to implement simple middleware to wrap around your API endpoints.

Deploy your own

How to use

Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:

bash
npx create-next-app --example api-routes-middleware api-routes-middleware-app
bash
yarn create next-app --example api-routes-middleware api-routes-middleware-app
bash
pnpm create next-app --example api-routes-middleware api-routes-middleware-app

Deploy it to the cloud with Vercel (Documentation).