ESC
NextStarterAI logo
Menu
On this page

Tutorials > Regular API Calls

Go into the /app/api folder – any file named route.js is your API endpoint! ✨ For an extra dash of simplicity, reach for the /libs/api.ts helper (it's like an axios wizard with interceptors).


Here is an example public API endpoint for collecting email leads:


/app/api/lead/route.ts
1 2 export async function POST(req: NextRequest) { 3 const body = await req.json(); 4 5 if (!body.email) { 6 return NextResponse.json({ error: "Email is required" }, { status: 400 }); 7 } 8 9 try { 10 const supabase = createRouteHandlerClient({ cookies }); 11 await supabase.from("leads").insert({ email: body.email }); 12 13 return NextResponse.json({}); 14 } catch (e) { 15 console.error(e); 16 return NextResponse.json({ error: e.message }, { status: 500 }); 17 } 18 } 19