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.

Luca Liberati Luca Liberati I work on monoliths and microservices, backends and frontends, manage K8s clusters and love to design apps architecture Daniel Vázquez Daniel Vázquez Software Engineer with over 10 years of experience on Startups, Government, big tech industry & consulting. Pratik Pratik SWE with 15+ years of experience building and maintaining web apps and extensive BE infrastructure Taufan Taufan I’m a product-focused engineer and tech leader who builds scalable systems and turns ideas into production-ready platforms. Over the past years, I’ve worked across startups and fast-moving teams, leading backend architecture, improving system reliability, and shipping products used by thousands of users. My strength is not just writing code — but connecting product vision, technical execution, and business impact. Bastien Labelle Bastien Labelle Full stack dev w/ 20+ years of experience Basel Issmail Basel Issmail ’m a Senior Full-Stack Developer and Tech Lead with experience designing and building scalable web platforms. I work across the full development lifecycle, from translating business requirements into technical architecture to delivering reliable production systems. My work focuses on modern web technologies, including TypeScript, Angular, Node.js, and cloud-based architectures. I enjoy solving complex technical problems and helping teams turn product ideas and prototypes into working platforms that can grow and scale. In addition to development, I often collaborate closely with product managers, business analysts, designers, and QA teams to ensure that solutions align with both technical and business goals. I enjoy working with startups and product teams where I can contribute both as a hands-on engineer and as a technical partner in designing and delivering impactful software. Caio Rodrigues Caio Rodrigues I'm a full-stack developer focused on building practical and scalable web applications. My main experience is with **React, TypeScript, and modern frontend architectures**, where I prioritize clean code, component reusability, and maintainable project structures. I have strong experience working with **dynamic forms, state management (Redux / React Hook Form), and complex data-driven interfaces**. I enjoy solving real-world problems by turning ideas into reliable software that companies can actually use in their daily operations. Beyond coding, I care about **software quality and architecture**, following best practices for componentization, code organization, and performance optimization. I'm also comfortable working across the stack when needed, integrating APIs, handling business logic, and helping transform prototypes into production-ready systems. My goal is always to deliver solutions that are **simple, efficient, and genuinely useful for the people using them.** Nam Tran Nam Tran 10 years as fullstack developer 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. Mehdi Ben Haddou Mehdi Ben Haddou - Founder of Chessigma (1M+ users) & many small projects - ex Founding Engineer @Uplane (YC F25) - ex Software Engineer @Amazon and @Booking.com

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