Creating API Routes
API routes are automatically created when you create Postgres Tables, Views, or Functions.
Create a table#
Create your first API route by creating a table called todos to store tasks.
This creates a corresponding route todos which can accept GET, POST, PATCH, & DELETE requests.
- Go to the Table editor page in the Dashboard.
- Click New Table and create a table with the name
todos. - Click Save.
- Click New Column and create a column with the name
taskand typetext. - Click Save.
- In the Integrations > Data API section of the Dashboard, expose specific tables like
todosor the functions you want to access. To automatically grant access for new tables and functions inpublic, enable Default privileges for new entities.
What it means to expose tables or functions via the API
Granting privileges (like select or execute) to roles such as anon or authenticated makes those tables or functions accessible through the Data API. Behind the scenes, the API checks your Postgres permissions—only objects with explicit grants are exposed, and all other access is denied by default.
API URL and keys#
Every Supabase project has a unique API URL. Your API is secured behind an API gateway which requires an API Key for every request.
To do this, you need to get the Project URL and key from the project's Connect dialog.
Changes to API keys
Supabase is deprecating the anon and service_role keys by the end of 2026. Use the publishable (sb_publishable_xxx) and secret (sb_secret_xxx) keys instead. For the reasoning behind the change, see the announcement on GitHub.
In most cases you can get keys from your project's Connect dialog. For every way to retrieve a key, including the CLI and the Management API, refer to Find your keys.
See API keys for a full explanation of all key types and their uses.
The REST API is accessible through the URL https://<project_ref>.supabase.co/rest/v1
Both of these routes require the key to be passed through an apikey header.
Using the API#
You can interact with your API directly via HTTP requests, or you can use the client libraries which we provide.
See how to make a request to the todos table which we created in the first step,
using the API URL (SUPABASE_URL) and Key (SUPABASE_PUBLISHABLE_KEY) we provided:
// Initialize the JS clientimport { createClient } from '@supabase/supabase-js'const supabase = createClient(SUPABASE_URL, SUPABASE_PUBLISHABLE_KEY)// Make a requestconst { data: todos, error } = await supabase.from('todos').select('*')JS Reference: select(),
insert(),
update(),
upsert(),
delete(),
rpc() (call Postgres functions).