Step-by-step guide to connect Supabase with PostgREST API: set up your project, configure the database, enable the API, secure it, and integrate with client apps.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Set Up Supabase Project
Step 2: Configure Supabase Database
Step 3: Enable API
Step 4: Configure PostgREST on Supabase
Example SQL for creating a table:
CREATE TABLE profiles (
id SERIAL PRIMARY KEY,
username TEXT UNIQUE,
bio TEXT
);
Step 5: Test PostgREST API
Example curl command to fetch all profiles:
curl -X GET 'https://your-project-ref.supabase.co/rest/v1/profiles' \\
-H "apikey: your_anon_key"
Step 6: Secure API Access
Example RLS policy to allow authenticated users to select from profiles:
CREATE POLICY "Allow authenticated read access"
ON profiles
FOR SELECT
USING (auth.role() = 'authenticated');
Step 7: Integrate PostgREST API with Client Applications
Example JavaScript fetch request:
fetch('https://your-project-ref.supabase.co/rest/v1/profiles', {
method: 'GET',
headers: {
'apikey': 'your_anon_key',
'Authorization': 'Bearer your_jwt_token'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.