Questions tagged [postgrest]

PostgREST serves a fully RESTful API from any existing PostgreSQL database. It provides a cleaner, more standards-compliant, faster API. It differs from the other emerging API servers by taking an opinionated stance on the full implementation of API by being operationally sound and simple to deploy, by delivering built-in security with JSON Web Tokens plus database roles, and by fully embracing the relational model.

Introduction

PostgREST is a standalone web server that turns your PostgreSQL database directly into a RESTful API. The structural constraints and permissions in the database determine the API endpoints and operations.

Motivation

Using PostgREST is an alternative to manual CRUD programming. Custom API servers suffer problems. Writing business logic often duplicates, ignores or hobbles database structure. Object-relational mapping is a leaky abstraction leading to slow imperative code. The PostgREST philosophy establishes a single declarative source of truth: the data itself.

Declarative Programming

It's easier to ask Postgres to join data for you and let its query planner figure out the details than to loop through rows yourself. It's easier to assign permissions to db objects than to add guards in controllers. (This is especially true for cascading permissions in data dependencies.) It's easier to set constraints than to litter code with sanity checks.

Leakproof Abstraction

There is no ORM involved. Creating new views happens in SQL with known performance implications. A database administrator can now create an API from scratch with no custom programming.

Embracing the Relational Model

In 1970 E. F. Codd criticized the then-dominant hierarchical model of databases in his article A Relational Model of Data for Large Shared Data Banks. Reading the article reveals a striking similarity between hierarchical databases and nested http routes. With PostgREST we attempt to use flexible filtering and embedding rather than nested routes.

One Thing Well

PostgREST has a focused scope. It works well with other tools like Nginx. This forces you to cleanly separate the data-centric CRUD operations from other concerns. Use a collection of sharp tools rather than building a big ball of mud.

136 questions
0
votes
1 answer

Supabase: get table count in rest mode

There is any way to get the table count in rest mode? I'm using query params like: https://urt.to.supabase/rest/v1/table?select=field,another_field I was googling it out but without success.
Diego Ulloa
  • 500
  • 8
  • 19
0
votes
1 answer

How to model PostgREST database to achieve social-network-like behaviour

This question might have a super easy answer, but as I am new to PostgreSQL/PostgREST, I am not sure how to achieve it. What I want to create is a schema/REST endpoint which allows me to query for posts posted by followed users. Currently, the…
0
votes
1 answer

PostGIS: Could not choose the best candidate function between: public.st_geomfromgeojson( => json), public.st_geomfromgeojson( => jsonb)

I've PostgREST in front of PostGIS and I want to call the st_geomfromgeojson function as described at https://postgrest.org/en/stable/api.html#stored-procedures. curl -X 'POST' \ 'http://postgrest-host:port/rpc/st_geomfromgeojson' \ -H 'accept:…
Moazzem Hossen
  • 2,276
  • 1
  • 19
  • 30
0
votes
1 answer

Reverse proxy in Apache + CentOS for HTTPS requests to PostgREST webserver

I would like to make https requests to my postgREST webserver, which by design doesn't support https. I spend several days now I don't know any further... My setup My server is running on CentOS 7.9.2009 I have a website domain that uses Wordpress…
JoeBe
  • 1,224
  • 3
  • 13
  • 28
0
votes
0 answers

PostgREST POST method converts Array of ints to text

I have a PostgreSQL function logschema.movement that returns a subset of the table logschema.movement, the function looks like this: CREATE OR REPLACE FUNCTION logschema.movement( "ids" bigint[], "date" TEXT) RETURNS SETOF…
Paul Müller
  • 103
  • 8
0
votes
1 answer

permission denied for schema api in tutorial

I'm trying a new thing, but I get stuck on the tutorial. When I follow step 4 of this tutorial: https://postgrest.org/en/v9.0/tutorials/tut0.html#step-4-create-database-for-api the SQL just runs without error. I can see the table+data. However, when…
doekman
  • 18,750
  • 20
  • 65
  • 86
0
votes
1 answer

postgres noinherit and grants

In the tutorial of postgrest is says: create role authenticator noinherit login password 'mysecretpassword'; grant web_anon to authenticator; My question is: why grant privileges of web_anon to authenticator, while authenticator in noinherit?
ericj
  • 2,138
  • 27
  • 44
0
votes
1 answer

OR operation with postgREST API

Consider I have two columns using which I want to fetch the rows. The condition would be WHERE column1="test" OR column2="test" How do I achieve this with postgREST API?
sai
  • 27
  • 4
0
votes
1 answer

Listing buildings' thematic data with 3D Web Map Client

I'm using 3D Importer/Export to import a .gml file to a Postgres 3D CityDB. Now I want to visualize the buildings on the map and list their characteristics. I've managed to visualize them, but as far as the characteristics go, I'm having some…
tdranv
  • 1,140
  • 11
  • 38
0
votes
1 answer

possibility of having a Like operator inside of the IN operator

Hoping this is the right tag to ask this question. Posted it before on a couple of forums, havent got the answer yet. Below is a query copied from the supabase website. const { data, error } = await supabase .from('users') …
Sumchans
  • 3,088
  • 6
  • 32
  • 59
0
votes
1 answer

How to send JSON body with curl to Postgrest

I'm trying to insert data on my Postgresql DB but I failed. So basically I can select the data with the query below; curl 10.127.18.18:3001/mytable I can get all rows with this request. I tried pretty much combination of the commands below but all…
yatta
  • 423
  • 1
  • 7
  • 22
0
votes
1 answer

Supabase / PostgREST: Deny select multiple

I am bulding a supabase app. Instead of a login every user gets a uuid (or multiple, if he wants to). Everyone that knows the uuid has full acces to the data behind this uuid. So basically the database is open to anyone, as long as you use any valid…
Patric
  • 1,489
  • 13
  • 28
0
votes
0 answers

How to make secure requests using Vuejs and postgREST

I am currently making a website for password reset. I use vue-cli, postgresql and postgrest. To secure the exchange of information between my website and the RESTful API I use a jwt that I put in the header of my requests. My problem is that when I…
0
votes
0 answers

PostgREST: Requests to volatile RPC with a single json parameter and which fires multiple triggers taking a very long time to complete - Solved

I am experiencing major performance issues when calling a stored procedure via PostgREST compared when calling it via psql. Both methods complete successfully, but the PostgREST takes ~1 min compared to 2 seconds with psql. There are many statement…
maxwst
  • 1
  • 2
0
votes
0 answers

Postgres - functions

We are using posgrest and wanted to create a function that creates a txt or csv file and wanted to download the file when function is called from rest endpoint. I tried COPY function to generate csv file and hoping to download load the file from…
balajiu
  • 1
  • 2