ESC
Tutorials > Regular API Calls
Go to the /server/api folder – name a file like hello.ts is your API endpoint! ✨ For an extra bit of simplicity, go to the /libs/api.ts helper (it's like an axios wizard with interceptors).
Here's a sample public API endpoint for gathering email leads:
/server/api/lead/index.post.ts
1import { createSSRClient } from "@/libs/supabase/server";
2 export default defineEventHandler(async (event) => {
3 const supabase = createSSRClient(event);
4 const body = await readBody(event);
5 if (!body.email) {
6 throw createError({ statusCode: 400, statusMessage: "Email is required" });
7 }
8 try {
9 await supabase.from("leads").insert({ email: body.email });
10
11 return {};
12 } catch (error) {
13 console.error(error);
14 throw error;
15 }
16 });