[breizhcamp, format 15min] une api rest et graphql sans code grâce à postgrest, sub0 et...

57
Une API REST sans code grâce à Postgrest, Sub0 et PostgreSQL

Upload: francois-guillaume-ribreau

Post on 28-Jan-2018

581 views

Category:

Software


0 download

TRANSCRIPT

Page 1: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Une API REST sans code grâce à Postgrest, Sub0 et PostgreSQL

Page 2: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL
Page 3: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

François-Guillaume Ribreau

Page 4: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

François-Guillaume Ribreau

—Ex-Bringr cofounder & CTO

Page 5: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

François-Guillaume Ribreau

—Ex-Bringr cofounder & CTO

Ex-Architect @iAdvize

Page 6: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

François-Guillaume Ribreau

—Ex-Bringr cofounder & CTO

Ex-Architect @iAdvizeArchitect & Head of development @Ouest-France

Page 7: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

François-Guillaume Ribreau

—Ex-Bringr cofounder & CTO

Ex-Architect @iAdvizeArchitect & Head of development @Ouest-France

🌟 Founded @imagecharts @Redsmin @mailpopin

Page 8: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

François-Guillaume Ribreau

—Ex-Bringr cofounder & CTO

Ex-Architect @iAdvizeArchitect & Head of development @Ouest-France

🌟 Founded @imagecharts @Redsmin @mailpopin

🚀 Trainer @EPSI_Nantes @UnivNantes

Page 9: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

François-Guillaume Ribreau

—Ex-Bringr cofounder & CTO

Ex-Architect @iAdvizeArchitect & Head of development @Ouest-France

🌟 Founded @imagecharts @Redsmin @mailpopin

🚀 Trainer @EPSI_Nantes @UnivNantes📢 Twitter/Github: @FGRibreau

Page 10: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL
Page 11: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

API?

Page 12: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

API?

Persistence API?

Page 13: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Single Source of Truth?

API?

Persistence API?

Page 14: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Single Source of Truth?

DRY?

API?

Persistence API?

Page 15: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

3-tier

Database

API

Frontend

Page 16: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

3-tier

Database(Tables/Views

Schema)

API(Models / ORM)

Front

Page 17: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Validation

Database(Schema (constraint))

API(Models / ORM

(validation))

Front(validation)

Page 18: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Relation

Database(Schema (referential

integrity))

API(Models / ORM

(relations))

Front

Page 19: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Authorization

Database(Users, roles,

policies)

API(Authorization middleware)

Front

Page 20: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Etc… 🕰

Database…

API…

Front

Page 21: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

API

DB

• HTTP request handling • Authentication• Authorization• Request Parsing • Request Validation • Database Communication • Database Response Handling • HTTP Response Building

Persistence API

your job

Page 22: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

API

SQLHTTP DB

• HTTP request handling • Authentication• Authorization• Request Parsing • Request Validation • Database Communication • Database Response Handling • HTTP Response Building

Persistence API

your job

Page 23: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

API

SQLHTTP DB

Persistence API

TL;DR: HTTP <-> SQL mapping

… with a lot of space for potential mistakes. your job

Page 24: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Postgrest DB

Persistence API

your job#SSoT #DRY

Page 25: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Are we serious?

Page 26: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Are we serious?

Page 27: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Postgrest DB

Persistence API

your job#SSoT #DRY

schema

Page 28: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Postgrest

Read / Write requests

(read) GET /projects (read) GET /account

(write) POST /rpc/signUp (write) POST /rpc/logIn

Page 29: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage projection, filtering, ordering?

Page 30: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

GET /people?age=gte.18&isStudent=is.true

How do you manage projection, filtering, ordering?

Page 31: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

GET /people?age=gte.18&isStudent=is.true

GET /people?select=age::text,height,weight

How do you manage projection, filtering, ordering?

Page 32: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

GET /people?age=gte.18&isStudent=is.true

GET /people?select=age::text,height,weight

GET /stuff?metadata->a->>b=eq.2

How do you manage projection, filtering, ordering?

Page 33: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

GET /people?age=gte.18&isStudent=is.true

GET /people?select=age::text,height,weight

GET /stuff?metadata->a->>b=eq.2

GET /projects?select=id,name,tasks{id,name}

&order=id.asc&tasks.order=name.asc

How do you manage projection, filtering, ordering?

Page 34: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage versioning?

Page 35: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage versioning?

public private

Page 36: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage versioning?

public private

authentication schema

i18n schema

app schema

….

schema

Page 37: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage versioning?

public private

v1_0 schema authentication schema

i18n schema

app schema

….

view schemastoredfn

projects signIn signUp

Page 38: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage versioning?

public private

v1_0 schema

v2_0 schema

authentication schema

i18n schema

app schema

….

view schemastoredfn

projects signIn signUp

projects logIn signUp

Page 39: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage authentication?

Page 40: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage authentication?

Page 41: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage authorization?

Page 42: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage authorization?

CREATE ROLE authenticator NOINHERIT LOGIN; CREATE ROLE anonymous; CREATE ROLE authenticated_user; GRANT anonymous, authenticated_user TO authenticator;

Page 43: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage authorization?

Page 44: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage authorization?

Row Level Security (PG 9.5+)

Page 45: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage authorization?

Row Level Security (PG 9.5+)ALTER TABLE app.project ENABLE ROW LEVEL SECURITY;

CREATE POLICY user_can_only_access_its_own_project on app.project — Any rows for which the expression returns false or null will not be visible to the user (in a SELECT), and will not be available for modification (in an UPDATE or DELETE)

using (user_id = current_setting('request.jwt.claim.user_id'))

Page 46: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage authorization?

Row Level Security (PG 9.5+)ALTER TABLE app.project ENABLE ROW LEVEL SECURITY;

CREATE POLICY user_can_only_access_its_own_project on app.project — Any rows for which the expression returns false or null will not be visible to the user (in a SELECT), and will not be available for modification (in an UPDATE or DELETE)

using (user_id = current_setting('request.jwt.claim.user_id'))

2 lines of SQLReliable security model (closed by default)

Declarative Expressive

Page 47: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage emails/3rd parties?

http://bit.ly/2oNbaKy

Page 48: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage emails/3rd parties?pg_notify (PG 9.2+)

http://bit.ly/2oNbaKy

Page 49: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage documentation?

Page 50: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage documentation?

OpenAPI (Swagger) formatautomatically extracted from schema

Page 51: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage code-reviews, tests, migrations?

Pivotal/trilogy pg_tag pg_unit pg_unit2

Page 52: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

How do you manage code-reviews, tests, migrations?

It’s just SQL.

Pivotal/trilogy pg_tag pg_unit pg_unit2

Page 53: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

One more thing

Page 54: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

PostgraphQL A GraphQL API created by reflection over a PostgreSQL schema. (NodeJS)

Page 55: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Sub0 ❤ GraphQL & REST API for your database

Page 56: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Free plans for Redis administration & monitoring

at redsmin.com

Questions?

@FGRibreau

No more server-side rendering pain, 1 url = 1 chart

image-charts.com

Page 57: [BreizhCamp, format 15min] Une api rest et GraphQL sans code grâce à PostgREST, sub0 et PostgreSQL

Free plans for Redis administration & monitoring

at redsmin.com

We are looking for Front-end Developers

twitter.com/iadvizetech

Questions?

@FGRibreau

No more server-side rendering pain, 1 url = 1 chart

image-charts.com