API Reference
Flow non espone un’API custom. I client (mobile + web) parlano direttamente con Supabase via tre canali:
- PostgREST — auto-generato da Postgres, copre tutto il CRUD delle tabelle con RLS applicato automaticamente
- Edge Functions — endpoint HTTP Deno/TypeScript per logica che non può vivere in puro SQL (notifiche, scoring, moderazione)
- Realtime — subscription a Postgres changes + broadcast channels
Niente gateway custom, niente serializzazione manuale. I tipi TypeScript/Dart sono auto-generati dallo schema.
PostgREST — CRUD automatico
Ogni tabella con RLS è un endpoint REST. Esempi:
// Tutti gli eventi pubblici (RLS filtra il resto)
const { data } = await supabase.from('events').select('*');
// Eventi nell'area, ordinati per data
const { data } = await supabase
.from('events')
.select('*, venue:venues(*)')
.gte('start_at', new Date().toISOString())
.order('start_at', { ascending: true });
// INSERT — RLS richiede user.id come organizer
const { data, error } = await supabase
.from('events')
.insert({ title, start_at, venue_id });Docs Supabase: PostgREST client.
Edge Functions
Funzioni deployate in supabase/functions/. Ciascuna esposta come endpoint HTTPS.
| Function | URL | Metodo | Trigger |
|---|---|---|---|
send-notification | /functions/v1/send-notification | POST | Database webhook (INSERT su notifications) |
process-rsvp | /functions/v1/process-rsvp | POST | Database webhook (INSERT/UPDATE su event_attendees) |
compute-recommendations | /functions/v1/compute-recommendations | POST | Cron (6h) + on-demand |
compute-matchmaking | /functions/v1/compute-matchmaking | POST | Chiamata dal client mobile |
moderate-content | /functions/v1/moderate-content | POST | Database webhook (INSERT su messages/comments) |
compute-connection-depth | /functions/v1/compute-connection-depth | POST | Database webhook (INSERT su event_attendees) |
evaluate-badges | /functions/v1/evaluate-badges | POST | Chiamata interna da process-rsvp |
Richiedere una Edge Function dal client:
const { data, error } = await supabase.functions.invoke('compute-matchmaking', {
body: { max_results: 20 },
});Deploy: npx supabase functions deploy <function-name>.
Realtime
Subscribe a cambi Postgres o a broadcast channels:
// Postgres change (notifiche dell'utente corrente)
const channel = supabase
.channel(`notifications:${userId}`)
.on(
'postgres_changes',
{ event: 'INSERT', schema: 'public', table: 'notifications', filter: `user_id=eq.${userId}` },
(payload) => { /* ... */ }
)
.subscribe();
// Broadcast (typing indicators, presence)
const chatChannel = supabase.channel(`chat:${chatId}`);
chatChannel.on('broadcast', { event: 'typing' }, (payload) => { /* ... */ });Docs: Supabase Realtime.
Autenticazione
Tutte le richieste sono autenticate via JWT Supabase Auth:
// Login
await supabase.auth.signInWithPassword({ email, password });
// Le chiamate successive attaccano il JWT automaticamente
const { data: { user } } = await supabase.auth.getUser();Le RLS policies leggono auth.uid() per autorizzare. Le Edge Functions
che devono bypassare RLS usano la service_role key via
_shared/supabase-client.ts.
Risorse
- Database Schema — tabelle + RLS policies
- Architettura Overview
- Supabase-only Migration Design