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
9
votes
4 answers

PostgREST on Google Cloud SQL: unix socket URI format?

Any of you with experience with PostgREST and Cloud SQL ? I have my SQL instance ready with open access (0.0.0.0/0) and I can access it with local PostGREST using the Cloud proxy app. Now I want to run Postgrest from an instance of the same…
J Dumont
  • 113
  • 6
8
votes
0 answers

Is there a way to generate the OpenAPI/Swagger definition from Postgres with object references?

I have a rest api using supabase/postgres(t) which generates it's own OpenAPI/Swagger definition. The problem is that this only contains the id fields but not actual references to the other tables. When generating a client with openapi-generater,…
5
votes
2 answers

PostgREST - Add authenticated user id on insert

I need to automatically add an author of an inserted row in one of its columns. I am using postgREST (using Supabase cloud service) and I don't want users to add whoever they want as the author. Is there a way to automatically add user id of the…
TomasB
  • 604
  • 5
  • 18
5
votes
3 answers

How do you specify DB_URI postgres DB connection string to instance running in Google Sql cloud?

Here's my scenario. I have set up an instance of Postgres DB running in the Google SQL cloud. It's up and running and if I whitelist my local IP, I can connect directly with no issue. I then have deployed a docker container (postGrest) which is a…
5
votes
1 answer

How to rewrite an Nginx GET request into POST?

My use case is that I have an email containing a "verify your email address" link. When the user clicks this link, the user agent performs a GET request like: GET http://widgetwerkz.example.com/confirm_email?challenge=LSXGMRUQMEBO The server will…
Chris
  • 3,000
  • 26
  • 43
5
votes
1 answer

PostgREST using limit and offset in subqueries or CTE

we are using PostgREST in our project for some quite complex database views. From some point on, when we are using limit and offset (x-range headers or query parameters) with sub-selects we get very high response times. From what we have read, it…
cip123
  • 63
  • 1
  • 6
4
votes
2 answers

How to solve for: net::ERR_CONNECTION_REFUSED when GET data to React?

I'm trying to get this API call to work using axios: const getData = () => { Axios.get("http://localhost:3000/security?select=symbol,company", {headers: {Authorization: 'Bearer 73Ntx3b6SwNXC7ANV3tw4wFfDdKntB26', …
andres
  • 1,558
  • 7
  • 24
  • 62
4
votes
1 answer

What is the usage of a NOLOGIN user in the postgresql?

I'm trying to understand the initial steps of PostgREST tutorial. In the mentioned tutorial, it is recommended to create two different roles named web_anon and authenticator as below: create role web_anon nologin; grant usage on schema api to…
Ebrahim Ghasemi
  • 5,850
  • 10
  • 52
  • 113
4
votes
1 answer

Authenticate postgrest api through keycloak

Postgrest APIs can be secured through inbuilt JWT tokens or through a third party service like Auth0, Okta or Keycloak (http://postgrest.org/en/v5.0/install.html) We want to consume JWT provided by a Keycloak only , but there is very limited…
user2590014
  • 71
  • 1
  • 5
3
votes
1 answer

How to add Supabase Order by in get request using Postman

I need to add order in supabase result while calling the supabase bash in postman. I am doing same in flutter like below Future getPropertiesFromBirmingham() async { var response = await client .from('properties') .limit(10) …
3
votes
0 answers

Auto-Incrementing IDs in Composite Primary Key

In my app, there are organizations that can create tasks. Instead of having a serial task ID, I would like to have an incrementing task ID for each organization ID. Just like in GitHub, where repo + issue number identifies the issue. Tasks look like…
ccssmnn
  • 306
  • 4
  • 11
3
votes
1 answer

PostgREST Transactions

I am using PostgREST to expose DB entities to a Springboot app which consumes those. I have two entities inside my DB which are Person and City. I would like to save the Person entity and the City at the same time, if any of those two fails I would…
OEH
  • 665
  • 11
  • 29
3
votes
3 answers

Can we use PostgREST with CockroachDB

PostgREST serves a fully RESTful API from any existing PostgreSQL database. CockroachDB promises distributed SQL advantages. CockroachDB is built to be largely compatible with PostgreSQL. Here is a detailed blog on this If we can bring these two…
Sairam Krish
  • 10,158
  • 3
  • 55
  • 67
3
votes
1 answer

PostgREST - How to create tables?

I want to create a new table using postgREST, but I was not able to find anything about this in the documentation. Is it possible to create tables? If yes, how? Sorry if this questions was already asked, but unfortunately I always found solutions…
Daniel P.
  • 43
  • 4
3
votes
1 answer

Insert/update PostGIS geometry column with PostgREST

I use the combination of PostgreSQL 12.1, PostGIS 3.0.0 and PostgREST 7.0.1 and I am extremely happy with this setup. There is an open enhancement for a wider PostGIS support in PostgREST and I am looking forward to it. I have a table with a…
ilowerp
  • 58
  • 5
1
2 3
9 10