Supabase API
Serviços para Dados
- REST API
- GraphQL API
- Realtime API
Finance API
Banco de Dados
https://supabase.com/dashboard/projects
Projeto invest-app (Table Editor)
create table investments (
id uuid not null default gen_random_uuid (),
name character varying null,
value bigint null,
origin character varying null,
category character varying null,
interest character varying null,
created_at timestamp with time zone not null default now(),
);
create table investments (
id uuid not null default gen_random_uuid (),
name character varying null,
value bigint null,
origin character varying null,
category character varying null,
interest character varying null,
created_at timestamp with time zone not null default now(),
);
insert into investments (name, value, origin, category, interest)
values
('Tesouro Selic 2029', 100000, 'Tesouro Nacional', 'Pós', '100% Selic'),
('Tesouro IPCA 2029', 10000, 'Tesouro Nacional', 'Pós', 'IPCA + 6,10%');
insert into investments (name, value, origin, category, interest)
values
('Tesouro Selic 2029', 100000, 'Tesouro Nacional', 'Pós', '100% Selic'),
('Tesouro IPCA 2029', 10000, 'Tesouro Nacional', 'Pós', 'IPCA + 6,10%');
Permitir Acesso Anônimo
Row Level Security (Authentication > Configuration > Policies):
CREATE POLICY "Allow public access"
ON "public"."investments"
as PERMISSIVE
FOR ALL
TO public
USING (true)
WITH CHECK (true);
CREATE POLICY "Allow public access"
ON "public"."investments"
as PERMISSIVE
FOR ALL
TO public
USING (true)
WITH CHECK (true);
Rotas
Código Fonte (Requisição | Rest Client)
Método | Caminho | Status | Resposta |
---|---|---|---|
POST | /rest/v1/investments | 201 | Cria um novo investimento |
GET | /rest/v1/investments?select=* | 200 | Retorna todos os investimentos |
GET | /rest/v1/investments?value=gt.10000 | 200 | Retorna todos os investimentos maior que 10000 |
GET | /rest/v1/investments?id=eq.1 | 200 | Retorna o investimento com id igual a 1 |
PATCH | /rest/v1/investments?id=eq.1 | 200 | Atualiza o investimento com id igual a 1 |
DELETE | /rest/v1/investments?id=eq.1 | 204 | Exclui o investimento com id igual a 1 |
Create a investment
PostgREST - Table and Views - Insert
Return
Prefer: return=minimal
Prefer: return=headers-only
Prefer: return=representation
/codes/package/supabase-api/.env.example
SUPABASE_KEY=
SUPABASE_URL=
/codes/package/supabase-api/.env.example
SUPABASE_KEY=
SUPABASE_URL=
# @host = https://xyz.supabase.co
@host = {{$dotenv SUPABASE_URL}}
@token = {{$dotenv SUPABASE_KEY}}
### Create a investment
# @name createInvestment
POST {{host}}/rest/v1/investments
apikey: {{token}}
Authorization: Bearer {{token}}
Content-Type: application/json
Prefer: return=representation
{
"name": "Tesouro Selic 2029",
"value": 10000,
"origin": "Tesouro Direto",
"category": "Pós",
"interest": "100% Selic"
}
# @host = https://xyz.supabase.co
@host = {{$dotenv SUPABASE_URL}}
@token = {{$dotenv SUPABASE_KEY}}
### Create a investment
# @name createInvestment
POST {{host}}/rest/v1/investments
apikey: {{token}}
Authorization: Bearer {{token}}
Content-Type: application/json
Prefer: return=representation
{
"name": "Tesouro Selic 2029",
"value": 10000,
"origin": "Tesouro Direto",
"category": "Pós",
"interest": "100% Selic"
}
$ SUPABASE_KEY=abc
$ curl -X POST 'https://xyz.supabase.co/rest/v1/investments' \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_KEY}" \
-H "Content-Type: application/json" \
-H "Prefer: return=representation" \
-d '{ "name": "Tesouro Selic 2029", "value": 10000, "origin": "Tesouro Nacional", "category": "Pós", "interest": "100% Selic" }'
$ SUPABASE_KEY=abc
$ curl -X POST 'https://xyz.supabase.co/rest/v1/investments' \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_KEY}" \
-H "Content-Type: application/json" \
-H "Prefer: return=representation" \
-d '{ "name": "Tesouro Selic 2029", "value": 10000, "origin": "Tesouro Nacional", "category": "Pós", "interest": "100% Selic" }'
Read investments
PostgREST - Table and Views - Read
@host = {{$dotenv SUPABASE_URL}}
@token = {{$dotenv SUPABASE_KEY}}
### Read investments
GET {{host}}/rest/v1/investments?select=*
apikey: {{token}}
Authorization: Bearer {{token}}
@host = {{$dotenv SUPABASE_URL}}
@token = {{$dotenv SUPABASE_KEY}}
### Read investments
GET {{host}}/rest/v1/investments?select=*
apikey: {{token}}
Authorization: Bearer {{token}}
$ SUPABASE_KEY=abc
$ curl 'https://xyz.supabase.co/rest/v1/investments?select=*' \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_KEY}"
$ SUPABASE_KEY=abc
$ curl 'https://xyz.supabase.co/rest/v1/investments?select=*' \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_KEY}"
Read a investment
PostgREST - Table and Views - Read
@host = {{$dotenv SUPABASE_URL}}
@token = {{$dotenv SUPABASE_KEY}}
@createdInvestmentId = {{createInvestment.response.body.$[0].id}}
### Read a investment
GET {{host}}/rest/v1/investments?id=eq.{{createdInvestmentId}}
apikey: {{token}}
Authorization: Bearer {{token}}
@host = {{$dotenv SUPABASE_URL}}
@token = {{$dotenv SUPABASE_KEY}}
@createdInvestmentId = {{createInvestment.response.body.$[0].id}}
### Read a investment
GET {{host}}/rest/v1/investments?id=eq.{{createdInvestmentId}}
apikey: {{token}}
Authorization: Bearer {{token}}
$ SUPABASE_KEY=abc
$ curl 'https://xyz.supabase.co/rest/v1/investments?id=eq.1' \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_KEY}"
$ SUPABASE_KEY=abc
$ curl 'https://xyz.supabase.co/rest/v1/investments?id=eq.1' \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_KEY}"
Update a investment
PostgREST - Table and Views - Update
### Update a investment
PATCH {{host}}/rest/v1/investments?id=eq.{{createdInvestmentId}}
apikey: {{token}}
Authorization: Bearer {{token}}
Content-Type: application/json
Prefer: return=representation
{
"value": 15000
}
### Update a investment
PATCH {{host}}/rest/v1/investments?id=eq.{{createdInvestmentId}}
apikey: {{token}}
Authorization: Bearer {{token}}
Content-Type: application/json
Prefer: return=representation
{
"value": 15000
}
$ SUPABASE_KEY=abc
$ curl -X PATCH 'https://xyz.supabase.co/rest/v1/investments?some_column=eq.someValue' \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_KEY}"\
-H "Content-Type: application/json" \
-H "Prefer: return=representation" \
-d '{ "value": 15000 }'
$ SUPABASE_KEY=abc
$ curl -X PATCH 'https://xyz.supabase.co/rest/v1/investments?some_column=eq.someValue' \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_KEY}"\
-H "Content-Type: application/json" \
-H "Prefer: return=representation" \
-d '{ "value": 15000 }'
Delete a investment
PostgREST - Table and Views - Delete
@host = {{$dotenv SUPABASE_URL}}
@token = {{$dotenv SUPABASE_KEY}}
@createdInvestmentId = {{createInvestment.response.body.$[0].id}}
### Delete a investment
DELETE {{host}}/rest/v1/investments?id=eq.{{createdInvestmentId}}
apikey: {{token}}
Authorization: Bearer {{token}}
@host = {{$dotenv SUPABASE_URL}}
@token = {{$dotenv SUPABASE_KEY}}
@createdInvestmentId = {{createInvestment.response.body.$[0].id}}
### Delete a investment
DELETE {{host}}/rest/v1/investments?id=eq.{{createdInvestmentId}}
apikey: {{token}}
Authorization: Bearer {{token}}
$ SUPABASE_KEY=abc
$ curl -X DELETE 'https://xyz.supabase.co/rest/v1/investments?some_column=eq.someValue' \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_KEY}"
$ SUPABASE_KEY=abc
$ curl -X DELETE 'https://xyz.supabase.co/rest/v1/investments?some_column=eq.someValue' \
-H "apikey: ${SUPABASE_KEY}" \
-H "Authorization: Bearer ${SUPABASE_KEY}"