SlideShare a Scribd company logo
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 1 di 24
Postgrest: la REST API per i database PostgreSQL 
Lucio Grenzi
l.grenzi@gmail.com
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 2 di 24
Who is this guy?
Delphi developer since 1999
IT Consultant 
Front end web developer
Postgresql addicted
      Nonantolando.blogspot.com
      lucio.grenzi
      lucio grenzi
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 3 di 24
AgendaAgenda
 NoBackend: what and why
 Postgresql: advantages 
 Postgrest features
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 4 di 24
NobackendNobackend
noBackend is an approach to decouple apps from backends, by abstracting 
backend tasks with frontend code. 
This  allows  frontend  developers  to  focus  on  user  experience  and  gives 
backend developers more flexibility on the implementation side.
­ nobackend.org ­
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 5 di 24
Our purposeOur purpose
Create apps / webapps that don't need a backend at all
Writing  business  logic  often  duplicates,  ignores  or  hobbles 
database structure
A single declarative source of truth: the data itself
How?
Using a REST API on top of your database
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 6 di 24
Build a backend in right wayBuild a backend in right way
SSL to rest api always!
Different schema to different port
Implement only what you need
Use webserver to route in the right way
Authentication done by JWT
Row level security feature introduced from Postgresql 9.5
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 7 di 24
Why schemas?Why schemas?
It allows many users to use one database without interfering 
with each other.
It organizes database objects into logical groups to make them 
more manageable.
Third­party applications can be put into separate schemas so 
they do not collide with the names of other objects.
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 8 di 24
Why PostgresqlWhy Postgresql
Versatility
json support
Custom languages (Plv8)
Lots of extensions
MVC logic inside the database
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 9 di 24
MVCMVC
MVC  is  an  architectural  design  pattern  that  encourages 
improved  application  organization  through  a  separation  of 
concerns. It enforces the isolation of business data (Models) 
from  user  interfaces  (Views),  with  a  third  component 
(Controllers)  traditionally  managing  logic,  user­input,  and 
coordination of Models and Views.
­ Developing Backbone.js Applications ­
By Addy Osmani
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 10 di 24
Build an applicationBuild an application
Focus on client related tecnology
Pick a frontend framework
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 11 di 24
PostgrestPostgrest
Cleaner and a more standards compliant API
Quick to get started
Nothing to install
Nothing to configure
Exchange data json format
Postgresql + Postgrest: combination that can give you a way to expose your 
data to other applications or web frontends.
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 12 di 24
Postgrest parameters/optionsPostgrest parameters/options
Usage: postgrest DB_URL (-a|--anonymous ROLE) [-s|--schema NAME]
[-p|--port PORT] [-j|--jwt-secret SECRET] [-o|--pool COUNT]
[-m|--max-rows COUNT]
PostgREST 0.3.2.0 / create a REST API to an existing Postgres database
Available options:
-h,--help Show this help text
DB_URL (REQUIRED) database connection string, e.g.
postgres://user:pass@host:port/db
-a,--anonymous ROLE (REQUIRED) postgres role to use for non-
authenticated requests
-s,--schema NAME schema to use for API routes (default: "public")
-p,--port PORT port number on which to run HTTP
server (default: 3000)
-j,--jwt-secret SECRET secret used to encrypt and decrypt JWT
tokens (default: "secret")
-o,--pool COUNT max connections in database pool (default: 10)
-m,--max-rows COUNT max rows in response (default: "infinity")
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 13 di 24
Postgrest - securityPostgrest - security
PostgREST is designed to keep the database at the center of API security
All authorization happens through database roles and permissions
Use json web sockets to
 authenticate API request
 authenticate  with external services
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 14 di 24
Postgrest – security with no jwtPostgrest – security with no jwt
If 
no JWT is present 
it the role is invalid
it does not contain the role claim
SET LOCAL ROLE anonymous;
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 15 di 24
Postgrest – security with jwtPostgrest – security with jwt
CREATE ROLE authenticator NOINHERIT LOGIN;
CREATE ROLE anonymous;
GRANT anonymous  TO authenticator;
postgrest postgres://pgday@localhost:5432/pgday ­­anonymous anon
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 16 di 24
Postgrest - performancesPostgrest - performances
Web application written in Haskell 
using Warp http server
It delegates as much calculation as possible to the database
Serializing JSON responses directly in SQL
Data validation
Authorization
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 17 di 24
Postgrest - VersioningPostgrest - Versioning
A  long­lived  API  needs  the  freedom  to  exist  in  multiple 
versions
PostgREST does versioning through database schemas
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 18 di 24
API matchesAPI matches
    POST ~ INSERT
    GET ~ SELECT
    PATCH ~ UPDATE
    PUT ~ UPSERT
    DELETE ~ DELETE
    Auth ~ user roles
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 19 di 24
API callsAPI calls
GET /customer?select=name, age, city,nation
POST /customer name, age, city,nation John,40,Boston,USA
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 20 di 24
Try postgrestTry postgrest
Source: https://github.com/begriffs/postgrest/
Docker image                 https://hub.docker.com/r/begriffs/postgrest/
Heroku
Postgrest: http://postgrest.com/
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 21 di 24
Postgrest clientPostgrest client
PostgREST JavaScript client provides  bindings and features 
to be used with PostgREST APIs.
Install with NPM in your project‘s folder.
 $ npm install postgrest­client
 
 var PostgREST = require('postgrest­client')    
 var Api = new PostgREST('https://postgrest.pgday.it')
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 22 di 24
Similar tool to PostgrestSimilar tool to Postgrest
PgREST http://pgre.st/
a JSON document store
PostGraphQL https://github.com/calebmer/postgraphql
a GraphQL schema created over a PostgreSQL schema
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 23 di 24
Questions?Questions?
PGDay.IT 2016 – 13 Dicembre 2016 - Prato 24 di 24

More Related Content

What's hot (20)

PPTX
ProxySQL for MySQL
Mydbops
 
PDF
Introduction to elasticsearch
pmanvi
 
PDF
Time series database, InfluxDB & PHP
Corley S.r.l.
 
PDF
Apache kafka performance(latency)_benchmark_v0.3
SANG WON PARK
 
PDF
SparkSQL: A Compiler from Queries to RDDs
Databricks
 
PDF
A Deep Dive into Query Execution Engine of Spark SQL
Databricks
 
PPTX
Grep - A powerful search utility
Nirajan Pant
 
PPTX
Mongo DB 성능최적화 전략
Jin wook
 
PDF
Apache Spark Core—Deep Dive—Proper Optimization
Databricks
 
PPTX
Introduction to Redis
TO THE NEW | Technology
 
PDF
SQL Operator.pdf
KalyankumarVenkat1
 
PDF
Anatomy of Data Frame API : A deep dive into Spark Data Frame API
datamantra
 
PPTX
Indexing the MySQL Index: Key to performance tuning
OSSCube
 
PPT
Solr vs ElasticSearch
Dikshant Shahi
 
PDF
PostgreSQL WAL for DBAs
PGConf APAC
 
PPTX
Cassandra Data Modeling - Practical Considerations @ Netflix
nkorla1share
 
PPTX
Транзакции и блокировки в MySql. Теория и практика
Nikolay Gondin
 
PDF
MariaDB 제품 소개
NeoClova
 
PPTX
MySQL_MariaDB로의_전환_기술요소-202212.pptx
NeoClova
 
PDF
Why Zsh is Cooler than Your Shell
jaguardesignstudio
 
ProxySQL for MySQL
Mydbops
 
Introduction to elasticsearch
pmanvi
 
Time series database, InfluxDB & PHP
Corley S.r.l.
 
Apache kafka performance(latency)_benchmark_v0.3
SANG WON PARK
 
SparkSQL: A Compiler from Queries to RDDs
Databricks
 
A Deep Dive into Query Execution Engine of Spark SQL
Databricks
 
Grep - A powerful search utility
Nirajan Pant
 
Mongo DB 성능최적화 전략
Jin wook
 
Apache Spark Core—Deep Dive—Proper Optimization
Databricks
 
Introduction to Redis
TO THE NEW | Technology
 
SQL Operator.pdf
KalyankumarVenkat1
 
Anatomy of Data Frame API : A deep dive into Spark Data Frame API
datamantra
 
Indexing the MySQL Index: Key to performance tuning
OSSCube
 
Solr vs ElasticSearch
Dikshant Shahi
 
PostgreSQL WAL for DBAs
PGConf APAC
 
Cassandra Data Modeling - Practical Considerations @ Netflix
nkorla1share
 
Транзакции и блокировки в MySql. Теория и практика
Nikolay Gondin
 
MariaDB 제품 소개
NeoClova
 
MySQL_MariaDB로의_전환_기술요소-202212.pptx
NeoClova
 
Why Zsh is Cooler than Your Shell
jaguardesignstudio
 

Viewers also liked (20)

PPTX
PostgREST Design Philosophy
begriffs
 
PDF
using Mithril.js + postgREST to build and consume API's
Antônio Roberto Silva
 
PDF
PgREST: Node.js in the Database
Audrey Tang
 
PDF
Django e il Rap Elia Contini
WEBdeBS
 
PDF
2007 - 应用系统脆弱性概论
Na Lee
 
PDF
Vim for Mere Mortals
Clayton Parker
 
PDF
The Django Book, Chapter 16: django.contrib
Tzu-ping Chung
 
PDF
PythonBrasil[8] closing
Tatiana Al-Chueyr
 
PPT
Load testing
Mindfire Solutions
 
PDF
The Django Book Chapter 9 - Django Workshop - Taipei.py
Tzu-ping Chung
 
PDF
NoSql Day - Apertura
WEBdeBS
 
PPTX
2016 py con2016_lightingtalk_php to python
Jiho Lee
 
PDF
Website optimization
Mindfire Solutions
 
PDF
라이트닝 토크 2015 파이콘
Jiho Lee
 
KEY
Overview of Testing Talks at Pycon
Jacqueline Kazil
 
PDF
User-centered open source
Jacqueline Kazil
 
PDF
Django - The Web framework for perfectionists with deadlines
Markus Zapke-Gründemann
 
ODP
Rabbitmq & Postgresql
Lucio Grenzi
 
PDF
NoSql Day - Chiusura
WEBdeBS
 
PDF
PyClab.__init__(self)
Tzu-ping Chung
 
PostgREST Design Philosophy
begriffs
 
using Mithril.js + postgREST to build and consume API's
Antônio Roberto Silva
 
PgREST: Node.js in the Database
Audrey Tang
 
Django e il Rap Elia Contini
WEBdeBS
 
2007 - 应用系统脆弱性概论
Na Lee
 
Vim for Mere Mortals
Clayton Parker
 
The Django Book, Chapter 16: django.contrib
Tzu-ping Chung
 
PythonBrasil[8] closing
Tatiana Al-Chueyr
 
Load testing
Mindfire Solutions
 
The Django Book Chapter 9 - Django Workshop - Taipei.py
Tzu-ping Chung
 
NoSql Day - Apertura
WEBdeBS
 
2016 py con2016_lightingtalk_php to python
Jiho Lee
 
Website optimization
Mindfire Solutions
 
라이트닝 토크 2015 파이콘
Jiho Lee
 
Overview of Testing Talks at Pycon
Jacqueline Kazil
 
User-centered open source
Jacqueline Kazil
 
Django - The Web framework for perfectionists with deadlines
Markus Zapke-Gründemann
 
Rabbitmq & Postgresql
Lucio Grenzi
 
NoSql Day - Chiusura
WEBdeBS
 
PyClab.__init__(self)
Tzu-ping Chung
 
Ad

Similar to Postgrest: the REST API for PostgreSQL databases (20)

PDF
[BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgR...
François-Guillaume Ribreau
 
PDF
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
François-Guillaume Ribreau
 
PDF
Writing infinite scalability web applications with PHP and PostgreSQL
Gabriele Bartolini
 
ODP
Patroni: PostgreSQL HA in the cloud
Lucio Grenzi
 
ODP
How to use Postgresql in order to handle Prometheus metrics storage
Lucio Grenzi
 
PDF
PostgreSQL 10; Long Awaited Enterprise Solutions
Julyanto SUTANDANG
 
PDF
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
Trivadis
 
PPTX
Postgresql
NexThoughts Technologies
 
PDF
Oracle to Postgres Migration - part 2
PgTraining
 
PDF
PostgreSQL Rocks Indonesia
PGConf APAC
 
PDF
SFScon14: Schrödinger’s elephant: why PostgreSQL can solve all your database ...
South Tyrol Free Software Conference
 
PPTX
Getting started with postgresql
botsplash.com
 
PDF
20240518 - VixulCon 2024 - The Rise of PostgreSQL_ Historic Trends and Modern...
Umair Shahid
 
PPTX
Module 5 Web Programing Setting Up Postgres.pptx
earningmoney9595
 
PDF
Bn 1016 demo postgre sql-online-training
conline training
 
PDF
PostgreSQL : Introduction
Open Source School
 
PDF
Don't panic! - Postgres introduction
Federico Campoli
 
PDF
An evening with Postgresql
Joshua Drake
 
PDF
PostgreSQL Prologue
Md. Golam Hossain
 
PDF
9.6_Course Material-Postgresql_002.pdf
sreedb2
 
[BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgR...
François-Guillaume Ribreau
 
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
François-Guillaume Ribreau
 
Writing infinite scalability web applications with PHP and PostgreSQL
Gabriele Bartolini
 
Patroni: PostgreSQL HA in the cloud
Lucio Grenzi
 
How to use Postgresql in order to handle Prometheus metrics storage
Lucio Grenzi
 
PostgreSQL 10; Long Awaited Enterprise Solutions
Julyanto SUTANDANG
 
Trivadis TechEvent 2017 PostgreSQL für die (Orakel) DBA by Ludovico Caldara
Trivadis
 
Oracle to Postgres Migration - part 2
PgTraining
 
PostgreSQL Rocks Indonesia
PGConf APAC
 
SFScon14: Schrödinger’s elephant: why PostgreSQL can solve all your database ...
South Tyrol Free Software Conference
 
Getting started with postgresql
botsplash.com
 
20240518 - VixulCon 2024 - The Rise of PostgreSQL_ Historic Trends and Modern...
Umair Shahid
 
Module 5 Web Programing Setting Up Postgres.pptx
earningmoney9595
 
Bn 1016 demo postgre sql-online-training
conline training
 
PostgreSQL : Introduction
Open Source School
 
Don't panic! - Postgres introduction
Federico Campoli
 
An evening with Postgresql
Joshua Drake
 
PostgreSQL Prologue
Md. Golam Hossain
 
9.6_Course Material-Postgresql_002.pdf
sreedb2
 
Ad

More from Lucio Grenzi (10)

ODP
Building serverless application on the Apache Openwhisk platform
Lucio Grenzi
 
PPTX
Full slidescr16
Lucio Grenzi
 
ODP
Use Ionic Framework to develop mobile application
Lucio Grenzi
 
ODP
Jenkins djangovillage
Lucio Grenzi
 
ODP
Geodjango and HTML 5
Lucio Grenzi
 
ODP
PLV8 - The PostgreSQL web side
Lucio Grenzi
 
ODP
Pg tap
Lucio Grenzi
 
PPT
Geodjango
Lucio Grenzi
 
PPT
Yui app-framework
Lucio Grenzi
 
PPT
node.js e Postgresql
Lucio Grenzi
 
Building serverless application on the Apache Openwhisk platform
Lucio Grenzi
 
Full slidescr16
Lucio Grenzi
 
Use Ionic Framework to develop mobile application
Lucio Grenzi
 
Jenkins djangovillage
Lucio Grenzi
 
Geodjango and HTML 5
Lucio Grenzi
 
PLV8 - The PostgreSQL web side
Lucio Grenzi
 
Pg tap
Lucio Grenzi
 
Geodjango
Lucio Grenzi
 
Yui app-framework
Lucio Grenzi
 
node.js e Postgresql
Lucio Grenzi
 

Recently uploaded (20)

PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Human Resources Information System (HRIS)
Amity University, Patna
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
GetOnCRM Speeds Up Agentforce 3 Deployment for Enterprise AI Wins.pdf
GetOnCRM Solutions
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Coefficient of Variance in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 

Postgrest: the REST API for PostgreSQL databases

  • 1. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 1 di 24 Postgrest: la REST API per i database PostgreSQL  Lucio Grenzi [email protected]
  • 2. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 2 di 24 Who is this guy? Delphi developer since 1999 IT Consultant  Front end web developer Postgresql addicted       Nonantolando.blogspot.com       lucio.grenzi       lucio grenzi
  • 3. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 3 di 24 AgendaAgenda  NoBackend: what and why  Postgresql: advantages   Postgrest features
  • 4. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 4 di 24 NobackendNobackend noBackend is an approach to decouple apps from backends, by abstracting  backend tasks with frontend code.  This  allows  frontend  developers  to  focus  on  user  experience  and  gives  backend developers more flexibility on the implementation side. ­ nobackend.org ­
  • 5. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 5 di 24 Our purposeOur purpose Create apps / webapps that don't need a backend at all Writing  business  logic  often  duplicates,  ignores  or  hobbles  database structure A single declarative source of truth: the data itself How? Using a REST API on top of your database
  • 6. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 6 di 24 Build a backend in right wayBuild a backend in right way SSL to rest api always! Different schema to different port Implement only what you need Use webserver to route in the right way Authentication done by JWT Row level security feature introduced from Postgresql 9.5
  • 7. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 7 di 24 Why schemas?Why schemas? It allows many users to use one database without interfering  with each other. It organizes database objects into logical groups to make them  more manageable. Third­party applications can be put into separate schemas so  they do not collide with the names of other objects.
  • 8. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 8 di 24 Why PostgresqlWhy Postgresql Versatility json support Custom languages (Plv8) Lots of extensions MVC logic inside the database
  • 9. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 9 di 24 MVCMVC MVC  is  an  architectural  design  pattern  that  encourages  improved  application  organization  through  a  separation  of  concerns. It enforces the isolation of business data (Models)  from  user  interfaces  (Views),  with  a  third  component  (Controllers)  traditionally  managing  logic,  user­input,  and  coordination of Models and Views. ­ Developing Backbone.js Applications ­ By Addy Osmani
  • 10. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 10 di 24 Build an applicationBuild an application Focus on client related tecnology Pick a frontend framework
  • 11. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 11 di 24 PostgrestPostgrest Cleaner and a more standards compliant API Quick to get started Nothing to install Nothing to configure Exchange data json format Postgresql + Postgrest: combination that can give you a way to expose your  data to other applications or web frontends.
  • 12. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 12 di 24 Postgrest parameters/optionsPostgrest parameters/options Usage: postgrest DB_URL (-a|--anonymous ROLE) [-s|--schema NAME] [-p|--port PORT] [-j|--jwt-secret SECRET] [-o|--pool COUNT] [-m|--max-rows COUNT] PostgREST 0.3.2.0 / create a REST API to an existing Postgres database Available options: -h,--help Show this help text DB_URL (REQUIRED) database connection string, e.g. postgres://user:pass@host:port/db -a,--anonymous ROLE (REQUIRED) postgres role to use for non- authenticated requests -s,--schema NAME schema to use for API routes (default: "public") -p,--port PORT port number on which to run HTTP server (default: 3000) -j,--jwt-secret SECRET secret used to encrypt and decrypt JWT tokens (default: "secret") -o,--pool COUNT max connections in database pool (default: 10) -m,--max-rows COUNT max rows in response (default: "infinity")
  • 13. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 13 di 24 Postgrest - securityPostgrest - security PostgREST is designed to keep the database at the center of API security All authorization happens through database roles and permissions Use json web sockets to  authenticate API request  authenticate  with external services
  • 14. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 14 di 24 Postgrest – security with no jwtPostgrest – security with no jwt If  no JWT is present  it the role is invalid it does not contain the role claim SET LOCAL ROLE anonymous;
  • 15. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 15 di 24 Postgrest – security with jwtPostgrest – security with jwt CREATE ROLE authenticator NOINHERIT LOGIN; CREATE ROLE anonymous; GRANT anonymous  TO authenticator; postgrest postgres://pgday@localhost:5432/pgday ­­anonymous anon
  • 16. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 16 di 24 Postgrest - performancesPostgrest - performances Web application written in Haskell  using Warp http server It delegates as much calculation as possible to the database Serializing JSON responses directly in SQL Data validation Authorization
  • 17. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 17 di 24 Postgrest - VersioningPostgrest - Versioning A  long­lived  API  needs  the  freedom  to  exist  in  multiple  versions PostgREST does versioning through database schemas
  • 18. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 18 di 24 API matchesAPI matches     POST ~ INSERT     GET ~ SELECT     PATCH ~ UPDATE     PUT ~ UPSERT     DELETE ~ DELETE     Auth ~ user roles
  • 19. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 19 di 24 API callsAPI calls GET /customer?select=name, age, city,nation POST /customer name, age, city,nation John,40,Boston,USA
  • 20. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 20 di 24 Try postgrestTry postgrest Source: https://github.com/begriffs/postgrest/ Docker image                 https://hub.docker.com/r/begriffs/postgrest/ Heroku Postgrest: http://postgrest.com/
  • 21. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 21 di 24 Postgrest clientPostgrest client PostgREST JavaScript client provides  bindings and features  to be used with PostgREST APIs. Install with NPM in your project‘s folder.  $ npm install postgrest­client    var PostgREST = require('postgrest­client')      var Api = new PostgREST('https://postgrest.pgday.it')
  • 22. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 22 di 24 Similar tool to PostgrestSimilar tool to Postgrest PgREST http://pgre.st/ a JSON document store PostGraphQL https://github.com/calebmer/postgraphql a GraphQL schema created over a PostgreSQL schema
  • 23. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 23 di 24 Questions?Questions?
  • 24. PGDay.IT 2016 – 13 Dicembre 2016 - Prato 24 di 24