DEV Community

Alex Spinov
Alex Spinov

Posted on

Supabase Has a Free API — Build a Full Backend Without Writing a Server

Firebase Alternative That Gives You Postgres

Supabase gives you a full Postgres database with instant REST and GraphQL APIs. Free tier includes 500MB storage, 2GB bandwidth, and 50K monthly active users.

Setup

  1. Create a project at supabase.com
  2. Copy your project URL and anon key
import { createClient } from "@supabase/supabase-js";

const supabase = createClient(
  "https://your-project.supabase.co",
  "your-anon-key"
);
Enter fullscreen mode Exit fullscreen mode

Insert Data

const { data, error } = await supabase
  .from("users")
  .insert([{ name: "John", email: "john@example.com", role: "admin" }]);

if (error) console.error(error);
else console.log("Inserted:", data);
Enter fullscreen mode Exit fullscreen mode

Query Data

// Simple select
const { data: users } = await supabase
  .from("users")
  .select("*")
  .eq("role", "admin")
  .order("created_at", { ascending: false })
  .limit(10);

// With relationships (automatic JOINs)
const { data: posts } = await supabase
  .from("posts")
  .select("title, content, users(name, email)")
  .eq("published", true);
Enter fullscreen mode Exit fullscreen mode

Real-time Subscriptions

const channel = supabase
  .channel("db-changes")
  .on("postgres_changes", 
    { event: "INSERT", schema: "public", table: "messages" },
    (payload) => {
      console.log("New message:", payload.new);
    }
  )
  .subscribe();
Enter fullscreen mode Exit fullscreen mode

Authentication (Built-in)

// Sign up
const { data, error } = await supabase.auth.signUp({
  email: "user@example.com",
  password: "secure_password"
});

// Sign in
const { data: session } = await supabase.auth.signInWithPassword({
  email: "user@example.com",
  password: "secure_password"
});

// OAuth (Google, GitHub, etc.)
const { data: oauth } = await supabase.auth.signInWithOAuth({
  provider: "github"
});
Enter fullscreen mode Exit fullscreen mode

File Storage

// Upload
const { data, error } = await supabase.storage
  .from("avatars")
  .upload("user1/avatar.png", file);

// Get public URL
const { data: url } = supabase.storage
  .from("avatars")
  .getPublicUrl("user1/avatar.png");
Enter fullscreen mode Exit fullscreen mode

Python Client

from supabase import create_client

supabase = create_client("https://your-project.supabase.co", "your-anon-key")

# Query
result = supabase.table("users").select("*").eq("role", "admin").execute()
print(result.data)

# Insert
supabase.table("users").insert({"name": "Jane", "email": "jane@example.com"}).execute()
Enter fullscreen mode Exit fullscreen mode

Supabase vs Firebase vs PlanetScale

Feature Supabase Firebase PlanetScale
Database Postgres NoSQL MySQL
Free storage 500MB 1GB 5GB
Auth Built-in Built-in No
Real-time Yes Yes No
SQL support Full No Full
Self-host Yes No No
Edge functions Yes Yes No

More tutorials | GitHub


More from me: 10 Dev Tools I Use Daily | 77 Scrapers on a Schedule | 150+ Free APIs

Top comments (0)