Chapter6 Setting Up Your Database
Route Handlers
Route Handlers allow you to create custom request handlers for a given route using Web Request and Response APIs.
Route Handlers are defined in a route.ts|js
file inside the app
directory.
export async function GET() {
try {
await client.sql`BEGIN`;
await seedUsers();
await seedCustomers();
await seedInvoices();
await seedRevenue();
await client.sql`COMMIT`;
return Response.json({ message: 'Database seeded successfully' });
} catch (error) {
await client.sql`ROLLBACK`;
return Response.json({ error }, { status: 500 });
}
}
localhost:3000/seedにgetリクエストが送られて、
上のgetメソッドが実行される。
Chapter7 Fetching Data
let's discuss the different ways you can fetch data for your application, and build out your dashboard overview page.