Created
February 24, 2023 14:53
-
-
Save ethanmick/ba361e93d1233ad9214af2b7228fb950 to your computer and use it in GitHub Desktop.
Next.js App API Route
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { prisma } from '@/lib/db' | |
import { NextResponse } from 'next/server' | |
export async function GET(request: Request) { | |
console.log('** GET /books') | |
const books = await prisma.book.findMany() | |
return NextResponse.json(books) | |
} | |
export async function POST(request: Request) { | |
console.log('** POST /books') | |
const { name, author } = await request.json() | |
const book = await prisma.book.create({ | |
data: { | |
name, | |
author | |
} | |
}) | |
return NextResponse.json(book) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment