Connecting FastAPI to Supabase
FastAPI to Supabase connection
Connection and testing process
Create this table in Supabase project.
CREATE TABLE students(
id BIGSERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(150) UNIQUE NOT NULL,
age INTEGER,
course VARCHAR(100)
);
GET vs. Post in FastAPI
- GET means “give me something.” You’re retrieving data.
- POST means “here, take this.” You’re submitting data for the server to act on.
The details of a request travel in different places:
- With GET, they go in the URL.
- With POST, they go in the request body.
GET: retrieving data
- A GET request asks the server for a resource.
- It shouldn’t change anything on the server, so repeating it ten times gives the same result and causes no harm.
POST: sending data to create or trigger something
- A POST request carries a payload, usually JSON, in the body.
- The server uses that payload to create a record, process a form, kick off a job, and so on.
FastAPI Security
Create this table in Supabase.
CREATE TABLE users (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL
);
JWT - JSON Web Token