본문 바로가기

Computer Programming/Next

Next.js 13 - Route Handler

v12의 API Routes가 개선됨 -> Route Hanlder

 

api 함수 1개 당 목적 별로 (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS). 눠서 처리할 수 있음

 

https://nextjs.org/docs/app/building-your-application/routing/route-handlers

 

Routing: Route Handlers | Next.js

Using App Router Features available in /app

nextjs.org

 

 

 

 

app/api/products/route.ts

import { getProducts } from "@/api/products/products";
import { NextResponse } from "next/server";

export async function GET(request: Request) {
  const products = await getProducts();
  return NextResponse.json({ products });
}