REST API

Build an API route in less than 2 minutes.

Create your first API route by creating a table called `todos` to store tasks.

Let's create our first REST route which we can query using cURL or the browser.

We'll create a database table called todos for storing tasks. This creates a corresponding API route /rest/v1/todos which can accept GET, POST, PATCH, & DELETE requests.

1

Set up a Supabase project with a 'todos' table

Create a new project in the Supabase Dashboard.

After your project is ready, create a table in your Supabase database. You can do this with either the Table interface or the SQL Editor.

2

Allow public access

Let's turn on Row Level Security for this table and allow public access.


_10
-- Turn on security
_10
alter table "todos"
_10
enable row level security;
_10
_10
-- Allow anonymous access
_10
create policy "Allow public access"
_10
on todos
_10
for select
_10
to anon
_10
using (true);

3

Insert some dummy data

Now we can add some data to our table which we can access through our API.


_10
insert into todos (task)
_10
values
_10
('Create tables'),
_10
('Enable security'),
_10
('Add data'),
_10
('Fetch data from the API');

4

Fetch the data

Find your API URL and Keys in your Dashboard API Settings. You can now query your "todos" table by appending /rest/v1/todos to the API URL.

Copy this block of code, substitute <PROJECT_REF> and <ANON_KEY>, then run it from a terminal.

Terminal

_10
curl 'https://<PROJECT_REF>.supabase.co/rest/v1/todos' \
_10
-H "apikey: <ANON_KEY>" \
_10
-H "Authorization: Bearer <ANON_KEY>"

Bonus

There are several options for accessing your data:

Browser

You can query the route in your browser, by appending the anon key as a query parameter:

https://<PROJECT_REF>.supabase.co/rest/v1/todos?apikey=<ANON_KEY>

Client libraries

We provide a number of Client Libraries.