v0 api

Next.js API Route Returns 404 on POST Request

Your Next.js API route returns 404 when making POST, PUT, DELETE requests, even though the route file exists. GET requests might work but other methods don't.

API routes fail when the handler function doesn't export HTTP method handlers, file structure doesn't match App Router conventions, or HTTP method routing is incorrect.

Error Messages You Might See

404 Not Found Method Not Allowed [api] Route not found POST handler not exported
404 Not FoundMethod Not Allowed[api] Route not foundPOST handler not exported

Common Causes

  1. Using page.ts instead of route.ts in API route directory
  2. Default export instead of named exports for HTTP methods (GET, POST, etc)
  3. Route file in pages directory (Pages Router) instead of app directory (App Router)
  4. Incorrect URL path matching route.ts file structure
  5. Missing HttpResponse wrapper in Vercel's Request/Response types

How to Fix It

Use route.ts: API routes must be named route.ts (not page.ts or api.ts) in app/api/your-route/ directory.

Export handlers: Export named async functions for each method:
export async function GET(request: Request) { ... }
export async function POST(request: Request) { ... }

App Router pattern: For /api/users endpoint, create app/api/users/route.ts file.

Test with correct method: Verify fetch call uses correct method: fetch(url, { method: 'POST' })

Real developers can help you.

Simon A. Simon A. I'm a backend developer building APIs, emulators, and interactive game systems. Professionally, I've developed Java/Spring reporting solutions, managed relational and NoSQL databases, and implemented CI/CD workflows. Tejas Chokhawala Tejas Chokhawala Full-stack engineer with 5 years experience building production web apps using React, Next.js and TypeScript. Focused on performance, clean architecture and shipping fast. Experienced with Supabase/Postgres backends, Stripe billing, and building AI-assisted developer tools. Luca Liberati Luca Liberati I work on monoliths and microservices, backends and frontends, manage K8s clusters and love to design apps architecture Antriksh Narang Antriksh Narang 5 years+ Experienced Dev (Specially in Web Development), can help in python, javascript, react, next.js and full stack web dev technologies. Yovel Cohen Yovel Cohen I got a lot of experience in building Long-horizon AI Agents in production, Backend apps that scale to millions of users and frontend knowledge as well. prajwalfullstack prajwalfullstack Hi Im a full stack developer, a vibe coded MVP to Market ready product, I'm here to help hanson1014 hanson1014 Full-stack developer experienced in fixing and deploying AI-generated apps from Lovable, Bolt.new, Cursor, and Replit. I specialize in debugging Supabase integration issues (auth flows, RLS policies, database connections), fixing broken deployments, resolving routing/blank screen problems, and cleaning up messy React/Vite codebases. I also build production apps with the Claude API and have shipped a Mac desktop dev tool (Nexterm from scratch. Based in Hong Kong, fast turnaround. Richard McSorley Richard McSorley Full-Stack Software Engineer with 8+ years building high-performance applications for enterprise clients. Shipped production systems at Walmart (4,000+ stores), Cigna (20M+ users), and Arkansas Blue Cross. 5 patents in retail/supply chain tech. Currently focused on AI integrations, automation tools, and TypeScript-first architectures. ISHANTDEEP SINGH ISHANTDEEP SINGH Senior Software Engineer with 7+ years of experience in React, JavaScript, TypeScript, Next.js, and Node.js. I’ve also worked as a tech lead for startups, owning end-to-end technical execution including architecture, development, scaling, and delivery. I bring a strong mix of hands-on coding, product thinking, and technical leadership, and I’m comfortable building products from scratch as well as improving and scaling existing systems. Matt Butler Matt Butler Software Engineer @ AWS

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently Asked Questions

What's the difference between route.ts and page.ts?

page.ts renders UI components. route.ts handles HTTP requests and exports GET/POST/etc handlers.

How do I handle multiple HTTP methods?

Export named functions in route.ts: export async function GET() {...} export async function POST() {...}

Why does my POST work in Postman but not fetch?

Check fetch headers include 'Content-Type': 'application/json' and body is JSON.stringify(data).

Related v0 Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help