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
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 });
}
'Computer Programming > Next' 카테고리의 다른 글
Next.js 13 - Redirects, Rewrites, Middleware, .env (0) | 2023.08.02 |
---|---|
Next.js 13 - loading.tsx , error.tsx, 이미지, 폰트 (0) | 2023.08.02 |
Next.js - fetch를 이용한 SSG, ISR, SSR, CSR 구현 옵션 (0) | 2023.08.01 |
Next.js - Server Component/ Client Components (0) | 2023.08.01 |
Next.js - Metadata (0) | 2023.08.01 |