Next.js ships with Route Handlers which provides an easy solution to build your own API. This example shows how to create multiple API endpoints with serverless functions, which can execute independently.
Deploy the example using Vercel or preview live with StackBlitz
Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:
npx create-next-app --example route-handlers route-handlers-appyarn create next-app --example route-handlers route-handlers-apppnpm create next-app --example route-handlers route-handlers-appDeploy it to the cloud with Vercel (Documentation).