SlideShare a Scribd company logo
API PLATFORM 2.1
When Symfony meets React
Kévin Dunglas
Founder of Les-Tilleuls.coop
Symfony Core Team
API Platform creator
@dunglas
Les-Tilleuls.coop
Self-managed company since 2011
100% owned by employees
19 people, 97% growth in 2016
Hiring in Lille, London and Amiens: jobs@les-tilleuls.coop
The Web of 2017
APIs: the Heart of the New Web
Central point to access data
Encapsulate the business logic
Same features available for all channels:
webapps, native mobile apps, IoT, enterprise, customers and providers
information systems
APIs are the foundations of this new web
SPA: Rich and Fast Webapps
Downloaded and executed only 1 time (first page load)
Use asynchronous HTTP requests to retrieve and modify the raw
data (usually JSON) using an API
Huge ecosystem: React/Redux, Angular, Vue, Ember… and probably a
new one while I’m speaking
Holds the presentation logic (good-bye Twig)
Standalone apps built using JavaScript, HTML and CSS
Modernized stack: ES2015/16/17, Babel, Webpack, Yarn, Flow,
TypeScript…
Native Mobile Apps
Use HTTP requests to retrieve and modify the raw data
(usually JSON) using an API but can also work offline
Can be developed using the JS stack: React Native, NativeScript
(Angular) - good-bye Cordova
Downloaded from stores (App Store, Google Play)
Look’n’Feel consistent with the platform (iOS or Android)
API Platform:
a Framework for 2017
Goals of the Framework
Support modern open API formats
Create a rock-solid API-first system in minutes
Batteries included: everything to create and consume the API
Be able to override, extend and customize everything
Features of API Platform 2.0
They Already Use API Platform
Getting
Started
Install
Get Docker
If you don’t already have it…
Install
Provided Docker images - PHP, Nginx, MySQL and Varnish (optional)
optimized for Symfony:
Create the database:
Download and extract the ZIP from api-platform.com
Browse http://localhost
$ docker-compose up
$ docker-compose exec php bin/console
doctrine:schema:create
A working
API
with just 1
PHP class
Your Turn!
Create your Own
Data Model
Write some PHPDoc (optional)
Add the @ApiResource annotation
Map its properties using the
Doctrine ORM (optional)
Update the database schema
$ docker-compose run web bin/console
doctrine:schema:update --force
Create a Plain Old PHP Object
Your API is
Ready!
Out of the Box Features
JSON-LD + Hydra encoding (HAL, XML, YAML, CSV and raw
JSON can be enabled through config and you can add yours)
Swagger documentation
Fully featured JavaScript UI using Swagger UI (now built
with React) available for all URLs of the API
Create (POST), Retrieve (GET item and lists), Update
(PUT) and Delete (DELETE) operations
Pagination for lists (30 items per page), fully configurable
What’s this Format?
JSON-LD and Hydra
Credit: Martin Fowler
http://martinfowler.com/articles/richardsonMaturityModel.html
JSON-LD
Standardized hypermedia format: W3C recommandation (2014)
Easy to use: a standard JSON document with some specials
keys (starting with @) and mapped with a context
Backed by Google, BBC, Microsoft, US & UK govs...
Compliant with technologies of the semantic web: RDF,
SPARQL, triple store...
JSON for Linked Data
Hydra
Make the API auto-discoverable by clients: all available
resources, properties, types and operations are described
Provide a standard format for common structures:
collections, paginations, filters, errors…
Documentation of the REST API in JSON-LD
Draft W3C
Data
Validation
Add
validation rules
Many validation constraints available
Ability to create custom constraints
Use the Symfony Validator
component
Relations
Add a Relation
Embedding Relations
Embedded Relations
How does it
Work?
REST
Wikipedia
Lexicon
Operation: action on an item or on a collection, usually through HTTP.
Internally a Symfony route.
DELETE /books/22
Resource: data exposed by the API, identified by an URL.
Internally a PHP object (an entity), externally a document
(JSON, HTML, XML…).
item: /books/22
collection: /books
Property: property of a resource. Internally, a class’ property. Externally
a document field (e.g. a JSON property). Typed.
It’s Symfony…
Configured with the most popular libraries
for APIs
Compatible with all existing bundles
Use Doctrine ORM by default (but you can
use the persistence system you want)
Symfony full stack application
…with something more
Properties’ types and relations are guessed using the Symfony
PropertyInfo component
The Metadata component guesses the API’s data
structure (resources and properties) form PHP classes
marked with @ApiResource
The structure is stored in an intermediate representation used to
serialize data and generate API docs (Hydra, Swagger…)
And Even More…
Symfony routes are automatically registered for all operations on
collections and items. By default:
item: GET, PUT, DELETE
collection: GET, POST
Data is normalized and denormalized using hypermedia normalizers
(JSON-LD, Hydra, HAL…) for the Symfony Serializer Component
Event-Driven Architecture
Client-Side
Tooling
Foundation of the most popular JS ecosystem out there
A JavaScript library for building user interfaces
Created by Facebook
JSX: write markup inside code
Just like Composer, but for
JavaScript.
$ curl -o- -L https://yarnpkg.com/
install.sh | bash
$ brew install yarn
Mac users:
Create React App
Babel: a JavaScript compiler (ES2015+, JSX, Flow…)
An app skeleton generator
All tools and configs to get started:
Webpack: a module bundler (compile and package your JS, CSS…)
$ yarn global add create-react-app
$ create-react-app my-app
$ cd my-app
$ yarn start
ESLint: identify and report bugs and bad patterns in the code
Integrated web server, live reloading, development and debugging tools
A Basic React Component
Adding some Properties
Adding some Properties
Configuring CORS headers
Loading Some Fixtures
Loading some Fixtures
$ docker-compose exec php bin/console
hautelook:fixtures:load
The Admin
Generator
API Platform Admin
Like Sonata or EasyAdminBundle but as a React SPA
Built on top of Admin On Rest (by Marmelab)
$ yarn add api-platform-admin
Material Design UI
Consume the API using AJAX
Automatically generate the admin by parsing the Hydra API doc
API Platform Admin
Customizing the Admin
The CRUD
Generator
API Platform Generate CRUD
Like Sensio Generator Bundle, but 100% client-side
Rock solid stack
$ yarn global add api-platform-generate-crud
Twitter Bootstrap support + accessibility (ARIA roles)
Consume the API using ES2015’s fetch()
Automatically generate files by parsing the Hydra API doc
The Stack
React, ES2015+, JSX
React Router: client-side routing library
Redux: an extensible container to manage the states of the app
Redux Form: manage form states
Redux Thunk: asynchronous actions (AJAX requests)
Optional: Twitter Bootstrap
Redux
css-tricks.com
Register the Generated code
The API Client
Actions and Creators
Reducers
Components…
…Components Wiring
The Form
React Native Generator
Coming
Soon!
Thanks!
Any questions?
api-platform/api-platform @ApiPlatform
https://api-platform.com
Extra: More
Features!
New in API Platform 2.1
An API as fast as a static website: builtin invalidation-based HTTP
cache (Varnish and CloudFlare support)
Client-side tools to consume the API built with React
and Redux: an app generator and an admin
Advanced, per-operation authorization rules
Native sub-resources support (e.g. GET /users/1/comments)
A ton of Developer eXperience improvements and better docs
Filters
Register the filter service (built-in or custom):
Map the filter to the resource
Filters
Content Negotiation
Adding a new format is as simple as creating a new
Symfony Normalizer for it
Built-in formats: JSON-LD, HAL, XML, YAML, CSV, JSON, HTML (UI)
To retrieve a resource in a given format: add an Accept
HTTP header or use the format name as file extension
Content Negotiation
Content Negotiation: HAL
Content Negotiation: XML
Events
The Schema Generator
Pick an existing data model from (resources and properties) from
schema.org:
$ docker-compose exec php
vendor/bin/schema generate-types src/ schema.yml
The Schema Generator
The Schema Generator
PHP classes, properties, getters and setters (PSR compliant)
Doctrine ORM mapping (including relations and mapped superclasses)
Validation constraints
Full PHPDoc extracted from schema human-readable descriptions
Mapping with schema.org's IRIs
The generator uses schema.org data to automatically bootstrap:
Relations between classes (supported by the API system too)
Rate this talk:
Follow me: @dunglas
joind.in/talk/7abdc

More Related Content

What's hot

Mohamed youssfi support architectures logicielles distribuées basées sue les ...
Mohamed youssfi support architectures logicielles distribuées basées sue les ...Mohamed youssfi support architectures logicielles distribuées basées sue les ...
Mohamed youssfi support architectures logicielles distribuées basées sue les ...
ENSET, Université Hassan II Casablanca
 
Presentation SOAP
 Presentation SOAP Presentation SOAP
Presentation SOAP
litayem bechir
 
Angular Framework présentation PPT LIGHT
Angular Framework présentation PPT LIGHTAngular Framework présentation PPT LIGHT
Angular Framework présentation PPT LIGHT
tayebbousfiha1
 
Formation JPA Avancé / Hibernate gratuite par Ippon 2014
Formation JPA Avancé / Hibernate gratuite par Ippon 2014Formation JPA Avancé / Hibernate gratuite par Ippon 2014
Formation JPA Avancé / Hibernate gratuite par Ippon 2014
Ippon
 
Initiation à Express js
Initiation à Express jsInitiation à Express js
Initiation à Express js
Abdoulaye Dieng
 
Support NodeJS avec TypeScript Express MongoDB
Support NodeJS avec TypeScript Express MongoDBSupport NodeJS avec TypeScript Express MongoDB
Support NodeJS avec TypeScript Express MongoDB
ENSET, Université Hassan II Casablanca
 
Un exemple élémentaire d'application MVC en PHP
Un exemple élémentaire d'application MVC en PHPUn exemple élémentaire d'application MVC en PHP
Un exemple élémentaire d'application MVC en PHP
Kristen Le Liboux
 
React state
React  stateReact  state
React state
Ducat
 
Telecharger Exercices corrigés PL/SQL
Telecharger Exercices corrigés PL/SQLTelecharger Exercices corrigés PL/SQL
Telecharger Exercices corrigés PL/SQL
webreaker
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
Harshit Choudhary
 
Architecture jee principe de inversion de controle et injection des dependances
Architecture jee principe de inversion de controle et injection des dependancesArchitecture jee principe de inversion de controle et injection des dependances
Architecture jee principe de inversion de controle et injection des dependances
ENSET, Université Hassan II Casablanca
 
Support de cours Spring M.youssfi
Support de cours Spring  M.youssfiSupport de cours Spring  M.youssfi
Support de cours Spring M.youssfi
ENSET, Université Hassan II Casablanca
 
Rest and the hypermedia constraint
Rest and the hypermedia constraintRest and the hypermedia constraint
Rest and the hypermedia constraint
Inviqa
 
Introduction à Laravel
Introduction à LaravelIntroduction à Laravel
Introduction à Laravel
Abdoulaye Dieng
 
React-cours.pdf
React-cours.pdfReact-cours.pdf
React-cours.pdf
Jaouad Assabbour
 
Site JEE de ECommerce Basé sur Spring IOC MVC Security JPA Hibernate
Site JEE de ECommerce  Basé sur Spring IOC MVC Security JPA HibernateSite JEE de ECommerce  Basé sur Spring IOC MVC Security JPA Hibernate
Site JEE de ECommerce Basé sur Spring IOC MVC Security JPA Hibernate
ENSET, Université Hassan II Casablanca
 
Higher Order Component React
Higher Order Component ReactHigher Order Component React
Higher Order Component React
Heber Silva
 
De 0 à Angular en 1h30! (french)
De 0 à Angular en 1h30! (french)De 0 à Angular en 1h30! (french)
De 0 à Angular en 1h30! (french)
Laurent Duveau
 
How To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native AppHow To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native App
Andolasoft Inc
 
Cours php & Mysql - 1ére partie
Cours php & Mysql - 1ére partieCours php & Mysql - 1ére partie
Cours php & Mysql - 1ére partie
kadzaki
 

What's hot (20)

Mohamed youssfi support architectures logicielles distribuées basées sue les ...
Mohamed youssfi support architectures logicielles distribuées basées sue les ...Mohamed youssfi support architectures logicielles distribuées basées sue les ...
Mohamed youssfi support architectures logicielles distribuées basées sue les ...
 
Presentation SOAP
 Presentation SOAP Presentation SOAP
Presentation SOAP
 
Angular Framework présentation PPT LIGHT
Angular Framework présentation PPT LIGHTAngular Framework présentation PPT LIGHT
Angular Framework présentation PPT LIGHT
 
Formation JPA Avancé / Hibernate gratuite par Ippon 2014
Formation JPA Avancé / Hibernate gratuite par Ippon 2014Formation JPA Avancé / Hibernate gratuite par Ippon 2014
Formation JPA Avancé / Hibernate gratuite par Ippon 2014
 
Initiation à Express js
Initiation à Express jsInitiation à Express js
Initiation à Express js
 
Support NodeJS avec TypeScript Express MongoDB
Support NodeJS avec TypeScript Express MongoDBSupport NodeJS avec TypeScript Express MongoDB
Support NodeJS avec TypeScript Express MongoDB
 
Un exemple élémentaire d'application MVC en PHP
Un exemple élémentaire d'application MVC en PHPUn exemple élémentaire d'application MVC en PHP
Un exemple élémentaire d'application MVC en PHP
 
React state
React  stateReact  state
React state
 
Telecharger Exercices corrigés PL/SQL
Telecharger Exercices corrigés PL/SQLTelecharger Exercices corrigés PL/SQL
Telecharger Exercices corrigés PL/SQL
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Architecture jee principe de inversion de controle et injection des dependances
Architecture jee principe de inversion de controle et injection des dependancesArchitecture jee principe de inversion de controle et injection des dependances
Architecture jee principe de inversion de controle et injection des dependances
 
Support de cours Spring M.youssfi
Support de cours Spring  M.youssfiSupport de cours Spring  M.youssfi
Support de cours Spring M.youssfi
 
Rest and the hypermedia constraint
Rest and the hypermedia constraintRest and the hypermedia constraint
Rest and the hypermedia constraint
 
Introduction à Laravel
Introduction à LaravelIntroduction à Laravel
Introduction à Laravel
 
React-cours.pdf
React-cours.pdfReact-cours.pdf
React-cours.pdf
 
Site JEE de ECommerce Basé sur Spring IOC MVC Security JPA Hibernate
Site JEE de ECommerce  Basé sur Spring IOC MVC Security JPA HibernateSite JEE de ECommerce  Basé sur Spring IOC MVC Security JPA Hibernate
Site JEE de ECommerce Basé sur Spring IOC MVC Security JPA Hibernate
 
Higher Order Component React
Higher Order Component ReactHigher Order Component React
Higher Order Component React
 
De 0 à Angular en 1h30! (french)
De 0 à Angular en 1h30! (french)De 0 à Angular en 1h30! (french)
De 0 à Angular en 1h30! (french)
 
How To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native AppHow To Manage API Request with AXIOS on a React Native App
How To Manage API Request with AXIOS on a React Native App
 
Cours php & Mysql - 1ére partie
Cours php & Mysql - 1ére partieCours php & Mysql - 1ére partie
Cours php & Mysql - 1ére partie
 

Similar to API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)

API Platform and Symfony: a Framework for API-driven Projects
API Platform and Symfony: a Framework for API-driven ProjectsAPI Platform and Symfony: a Framework for API-driven Projects
API Platform and Symfony: a Framework for API-driven Projects
Les-Tilleuls.coop
 
API Platform: Full Stack Framework Resurrection
API Platform: Full Stack Framework ResurrectionAPI Platform: Full Stack Framework Resurrection
API Platform: Full Stack Framework Resurrection
Les-Tilleuls.coop
 
Creating hypermedia APIs in a few minutes using the API Platform framework
Creating hypermedia APIs in a few minutes using the API Platform frameworkCreating hypermedia APIs in a few minutes using the API Platform framework
Creating hypermedia APIs in a few minutes using the API Platform framework
Les-Tilleuls.coop
 
API Platform: A Framework for API-driven Projects
API Platform: A Framework for API-driven ProjectsAPI Platform: A Framework for API-driven Projects
API Platform: A Framework for API-driven Projects
Les-Tilleuls.coop
 
A high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTSA high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTS
Smile I.T is open
 
High quality ap is with api platform
High quality ap is with api platformHigh quality ap is with api platform
High quality ap is with api platform
Nelson Kopliku
 
UIT: Our Skills
UIT: Our SkillsUIT: Our Skills
UIT: Our Skillsuitpramati
 
Programming With Amazon, Google, And E Bay
Programming With Amazon, Google, And E BayProgramming With Amazon, Google, And E Bay
Programming With Amazon, Google, And E BayPhi Jack
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
ASG
 
Leveraging Hadoop in Polyglot Architectures
Leveraging Hadoop in Polyglot ArchitecturesLeveraging Hadoop in Polyglot Architectures
Leveraging Hadoop in Polyglot Architectures
Thanigai Vellore
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop Overview
Shubhra Kar
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
Antonio Peric-Mazar
 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Jesus Manuel Olivas
 
Past, Present and Future of APIs of Mobile and Web Apps
Past, Present and Future of APIs of Mobile and Web AppsPast, Present and Future of APIs of Mobile and Web Apps
Past, Present and Future of APIs of Mobile and Web Apps
SmartBear
 
Mastering the IoT With JavaScript and C++ - Günter Obiltschnig
Mastering the IoT With JavaScript and C++ - Günter ObiltschnigMastering the IoT With JavaScript and C++ - Günter Obiltschnig
Mastering the IoT With JavaScript and C++ - Günter Obiltschnig
WithTheBest
 
Advanced Web Development
Advanced Web DevelopmentAdvanced Web Development
Advanced Web Development
Robert J. Stein
 
Building a modern application using Symfony API Platform and GatsbyJS PHP QRO
Building a modern application using  Symfony API Platform and GatsbyJS PHP QROBuilding a modern application using  Symfony API Platform and GatsbyJS PHP QRO
Building a modern application using Symfony API Platform and GatsbyJS PHP QRO
Jesus Manuel Olivas
 
Intro lift
Intro liftIntro lift
Intro lift
Knoldus Inc.
 
AJAX Frameworks
AJAX FrameworksAJAX Frameworks
AJAX Frameworks
shank
 
20140527 - APIcon SF - Workshop #2 - Document and manage Java-based web APIs
20140527 - APIcon SF - Workshop #2 - Document and manage Java-based web APIs20140527 - APIcon SF - Workshop #2 - Document and manage Java-based web APIs
20140527 - APIcon SF - Workshop #2 - Document and manage Java-based web APIs
Jerome Louvel
 

Similar to API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017) (20)

API Platform and Symfony: a Framework for API-driven Projects
API Platform and Symfony: a Framework for API-driven ProjectsAPI Platform and Symfony: a Framework for API-driven Projects
API Platform and Symfony: a Framework for API-driven Projects
 
API Platform: Full Stack Framework Resurrection
API Platform: Full Stack Framework ResurrectionAPI Platform: Full Stack Framework Resurrection
API Platform: Full Stack Framework Resurrection
 
Creating hypermedia APIs in a few minutes using the API Platform framework
Creating hypermedia APIs in a few minutes using the API Platform frameworkCreating hypermedia APIs in a few minutes using the API Platform framework
Creating hypermedia APIs in a few minutes using the API Platform framework
 
API Platform: A Framework for API-driven Projects
API Platform: A Framework for API-driven ProjectsAPI Platform: A Framework for API-driven Projects
API Platform: A Framework for API-driven Projects
 
A high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTSA high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTS
 
High quality ap is with api platform
High quality ap is with api platformHigh quality ap is with api platform
High quality ap is with api platform
 
UIT: Our Skills
UIT: Our SkillsUIT: Our Skills
UIT: Our Skills
 
Programming With Amazon, Google, And E Bay
Programming With Amazon, Google, And E BayProgramming With Amazon, Google, And E Bay
Programming With Amazon, Google, And E Bay
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
 
Leveraging Hadoop in Polyglot Architectures
Leveraging Hadoop in Polyglot ArchitecturesLeveraging Hadoop in Polyglot Architectures
Leveraging Hadoop in Polyglot Architectures
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop Overview
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...Creating a modern web application using Symfony API Platform, ReactJS and Red...
Creating a modern web application using Symfony API Platform, ReactJS and Red...
 
Past, Present and Future of APIs of Mobile and Web Apps
Past, Present and Future of APIs of Mobile and Web AppsPast, Present and Future of APIs of Mobile and Web Apps
Past, Present and Future of APIs of Mobile and Web Apps
 
Mastering the IoT With JavaScript and C++ - Günter Obiltschnig
Mastering the IoT With JavaScript and C++ - Günter ObiltschnigMastering the IoT With JavaScript and C++ - Günter Obiltschnig
Mastering the IoT With JavaScript and C++ - Günter Obiltschnig
 
Advanced Web Development
Advanced Web DevelopmentAdvanced Web Development
Advanced Web Development
 
Building a modern application using Symfony API Platform and GatsbyJS PHP QRO
Building a modern application using  Symfony API Platform and GatsbyJS PHP QROBuilding a modern application using  Symfony API Platform and GatsbyJS PHP QRO
Building a modern application using Symfony API Platform and GatsbyJS PHP QRO
 
Intro lift
Intro liftIntro lift
Intro lift
 
AJAX Frameworks
AJAX FrameworksAJAX Frameworks
AJAX Frameworks
 
20140527 - APIcon SF - Workshop #2 - Document and manage Java-based web APIs
20140527 - APIcon SF - Workshop #2 - Document and manage Java-based web APIs20140527 - APIcon SF - Workshop #2 - Document and manage Java-based web APIs
20140527 - APIcon SF - Workshop #2 - Document and manage Java-based web APIs
 

More from Les-Tilleuls.coop

Symfony on steroids
: Vue.js, Mercure, Panther
Symfony on steroids
: Vue.js, Mercure, PantherSymfony on steroids
: Vue.js, Mercure, Panther
Symfony on steroids
: Vue.js, Mercure, Panther
Les-Tilleuls.coop
 
Official "push" and real-time capabilities for Symfony and API Platform (Merc...
Official "push" and real-time capabilities for Symfony and API Platform (Merc...Official "push" and real-time capabilities for Symfony and API Platform (Merc...
Official "push" and real-time capabilities for Symfony and API Platform (Merc...
Les-Tilleuls.coop
 
Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...
Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...
Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...
Les-Tilleuls.coop
 
HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...
HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...
HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...
Les-Tilleuls.coop
 
Panther: test your Symfony apps with real web browsers
Panther: test your Symfony apps with real web browsersPanther: test your Symfony apps with real web browsers
Panther: test your Symfony apps with real web browsers
Les-Tilleuls.coop
 
Symfony 2 : Performances et Optimisations
Symfony 2 : Performances et OptimisationsSymfony 2 : Performances et Optimisations
Symfony 2 : Performances et Optimisations
Les-Tilleuls.coop
 
Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014
Les-Tilleuls.coop
 
Workshop HTML5 : référencement grâce à la sémantique
Workshop HTML5 : référencement grâce à la sémantiqueWorkshop HTML5 : référencement grâce à la sémantique
Workshop HTML5 : référencement grâce à la sémantique
Les-Tilleuls.coop
 
Atelier #3 intégration html
Atelier #3 intégration htmlAtelier #3 intégration html
Atelier #3 intégration html
Les-Tilleuls.coop
 
Atelier #2 initiation à css
Atelier #2 initiation à cssAtelier #2 initiation à css
Atelier #2 initiation à css
Les-Tilleuls.coop
 
Atelier initiation au html5
Atelier initiation au html5Atelier initiation au html5
Atelier initiation au html5
Les-Tilleuls.coop
 

More from Les-Tilleuls.coop (11)

Symfony on steroids
: Vue.js, Mercure, Panther
Symfony on steroids
: Vue.js, Mercure, PantherSymfony on steroids
: Vue.js, Mercure, Panther
Symfony on steroids
: Vue.js, Mercure, Panther
 
Official "push" and real-time capabilities for Symfony and API Platform (Merc...
Official "push" and real-time capabilities for Symfony and API Platform (Merc...Official "push" and real-time capabilities for Symfony and API Platform (Merc...
Official "push" and real-time capabilities for Symfony and API Platform (Merc...
 
Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...
Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...
Progressively enhance your Symfony 4 app using Vue, API Platform, Mercure and...
 
HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...
HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...
HTTP/2: speed up your apps and dispatch real time updates (Symfony and API Pl...
 
Panther: test your Symfony apps with real web browsers
Panther: test your Symfony apps with real web browsersPanther: test your Symfony apps with real web browsers
Panther: test your Symfony apps with real web browsers
 
Symfony 2 : Performances et Optimisations
Symfony 2 : Performances et OptimisationsSymfony 2 : Performances et Optimisations
Symfony 2 : Performances et Optimisations
 
Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014Diaporama du sfPot Lillois du 20 mars 2014
Diaporama du sfPot Lillois du 20 mars 2014
 
Workshop HTML5 : référencement grâce à la sémantique
Workshop HTML5 : référencement grâce à la sémantiqueWorkshop HTML5 : référencement grâce à la sémantique
Workshop HTML5 : référencement grâce à la sémantique
 
Atelier #3 intégration html
Atelier #3 intégration htmlAtelier #3 intégration html
Atelier #3 intégration html
 
Atelier #2 initiation à css
Atelier #2 initiation à cssAtelier #2 initiation à css
Atelier #2 initiation à css
 
Atelier initiation au html5
Atelier initiation au html5Atelier initiation au html5
Atelier initiation au html5
 

Recently uploaded

History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
laozhuseo02
 
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptxLiving-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
TristanJasperRamos
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
Himani415946
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
JungkooksNonexistent
 
Output determination SAP S4 HANA SAP SD CC
Output determination SAP S4 HANA SAP SD CCOutput determination SAP S4 HANA SAP SD CC
Output determination SAP S4 HANA SAP SD CC
ShahulHameed54211
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Sanjeev Rampal
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
3ipehhoa
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
nirahealhty
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
laozhuseo02
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
natyesu
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
JeyaPerumal1
 

Recently uploaded (16)

History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptxLiving-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
Living-in-IT-era-Module-7-Imaging-and-Design-for-Social-Impact.pptx
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
Output determination SAP S4 HANA SAP SD CC
Output determination SAP S4 HANA SAP SD CCOutput determination SAP S4 HANA SAP SD CC
Output determination SAP S4 HANA SAP SD CC
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
BASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptxBASIC C++ lecture NOTE C++ lecture 3.pptx
BASIC C++ lecture NOTE C++ lecture 3.pptx
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
 

API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)

  • 1. API PLATFORM 2.1 When Symfony meets React
  • 2. Kévin Dunglas Founder of Les-Tilleuls.coop Symfony Core Team API Platform creator @dunglas
  • 3. Les-Tilleuls.coop Self-managed company since 2011 100% owned by employees 19 people, 97% growth in 2016 Hiring in Lille, London and Amiens: jobs@les-tilleuls.coop
  • 4. The Web of 2017
  • 5.
  • 6. APIs: the Heart of the New Web Central point to access data Encapsulate the business logic Same features available for all channels: webapps, native mobile apps, IoT, enterprise, customers and providers information systems APIs are the foundations of this new web
  • 7. SPA: Rich and Fast Webapps Downloaded and executed only 1 time (first page load) Use asynchronous HTTP requests to retrieve and modify the raw data (usually JSON) using an API Huge ecosystem: React/Redux, Angular, Vue, Ember… and probably a new one while I’m speaking Holds the presentation logic (good-bye Twig) Standalone apps built using JavaScript, HTML and CSS Modernized stack: ES2015/16/17, Babel, Webpack, Yarn, Flow, TypeScript…
  • 8. Native Mobile Apps Use HTTP requests to retrieve and modify the raw data (usually JSON) using an API but can also work offline Can be developed using the JS stack: React Native, NativeScript (Angular) - good-bye Cordova Downloaded from stores (App Store, Google Play) Look’n’Feel consistent with the platform (iOS or Android)
  • 10. Goals of the Framework Support modern open API formats Create a rock-solid API-first system in minutes Batteries included: everything to create and consume the API Be able to override, extend and customize everything
  • 11. Features of API Platform 2.0
  • 12. They Already Use API Platform
  • 14. Install Get Docker If you don’t already have it…
  • 15. Install Provided Docker images - PHP, Nginx, MySQL and Varnish (optional) optimized for Symfony: Create the database: Download and extract the ZIP from api-platform.com Browse http://localhost $ docker-compose up $ docker-compose exec php bin/console doctrine:schema:create
  • 16.
  • 17. A working API with just 1 PHP class
  • 19. Create your Own Data Model Write some PHPDoc (optional) Add the @ApiResource annotation Map its properties using the Doctrine ORM (optional) Update the database schema $ docker-compose run web bin/console doctrine:schema:update --force Create a Plain Old PHP Object
  • 21. Out of the Box Features JSON-LD + Hydra encoding (HAL, XML, YAML, CSV and raw JSON can be enabled through config and you can add yours) Swagger documentation Fully featured JavaScript UI using Swagger UI (now built with React) available for all URLs of the API Create (POST), Retrieve (GET item and lists), Update (PUT) and Delete (DELETE) operations Pagination for lists (30 items per page), fully configurable
  • 22.
  • 25. JSON-LD Standardized hypermedia format: W3C recommandation (2014) Easy to use: a standard JSON document with some specials keys (starting with @) and mapped with a context Backed by Google, BBC, Microsoft, US & UK govs... Compliant with technologies of the semantic web: RDF, SPARQL, triple store... JSON for Linked Data
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32. Hydra Make the API auto-discoverable by clients: all available resources, properties, types and operations are described Provide a standard format for common structures: collections, paginations, filters, errors… Documentation of the REST API in JSON-LD Draft W3C
  • 33.
  • 34.
  • 35.
  • 37. Add validation rules Many validation constraints available Ability to create custom constraints Use the Symfony Validator component
  • 38.
  • 41.
  • 46. Lexicon Operation: action on an item or on a collection, usually through HTTP. Internally a Symfony route. DELETE /books/22 Resource: data exposed by the API, identified by an URL. Internally a PHP object (an entity), externally a document (JSON, HTML, XML…). item: /books/22 collection: /books Property: property of a resource. Internally, a class’ property. Externally a document field (e.g. a JSON property). Typed.
  • 47. It’s Symfony… Configured with the most popular libraries for APIs Compatible with all existing bundles Use Doctrine ORM by default (but you can use the persistence system you want) Symfony full stack application
  • 48. …with something more Properties’ types and relations are guessed using the Symfony PropertyInfo component The Metadata component guesses the API’s data structure (resources and properties) form PHP classes marked with @ApiResource The structure is stored in an intermediate representation used to serialize data and generate API docs (Hydra, Swagger…)
  • 49. And Even More… Symfony routes are automatically registered for all operations on collections and items. By default: item: GET, PUT, DELETE collection: GET, POST Data is normalized and denormalized using hypermedia normalizers (JSON-LD, Hydra, HAL…) for the Symfony Serializer Component
  • 52.
  • 53. Foundation of the most popular JS ecosystem out there A JavaScript library for building user interfaces Created by Facebook JSX: write markup inside code
  • 54.
  • 55. Just like Composer, but for JavaScript. $ curl -o- -L https://yarnpkg.com/ install.sh | bash $ brew install yarn Mac users:
  • 56. Create React App Babel: a JavaScript compiler (ES2015+, JSX, Flow…) An app skeleton generator All tools and configs to get started: Webpack: a module bundler (compile and package your JS, CSS…) $ yarn global add create-react-app $ create-react-app my-app $ cd my-app $ yarn start ESLint: identify and report bugs and bad patterns in the code Integrated web server, live reloading, development and debugging tools
  • 57.
  • 58. A Basic React Component
  • 59.
  • 64. Loading some Fixtures $ docker-compose exec php bin/console hautelook:fixtures:load
  • 66. API Platform Admin Like Sonata or EasyAdminBundle but as a React SPA Built on top of Admin On Rest (by Marmelab) $ yarn add api-platform-admin Material Design UI Consume the API using AJAX Automatically generate the admin by parsing the Hydra API doc
  • 68.
  • 70.
  • 72. API Platform Generate CRUD Like Sensio Generator Bundle, but 100% client-side Rock solid stack $ yarn global add api-platform-generate-crud Twitter Bootstrap support + accessibility (ARIA roles) Consume the API using ES2015’s fetch() Automatically generate files by parsing the Hydra API doc
  • 73. The Stack React, ES2015+, JSX React Router: client-side routing library Redux: an extensible container to manage the states of the app Redux Form: manage form states Redux Thunk: asynchronous actions (AJAX requests) Optional: Twitter Bootstrap
  • 75.
  • 76.
  • 78.
  • 88. New in API Platform 2.1 An API as fast as a static website: builtin invalidation-based HTTP cache (Varnish and CloudFlare support) Client-side tools to consume the API built with React and Redux: an app generator and an admin Advanced, per-operation authorization rules Native sub-resources support (e.g. GET /users/1/comments) A ton of Developer eXperience improvements and better docs
  • 89. Filters Register the filter service (built-in or custom): Map the filter to the resource
  • 91. Content Negotiation Adding a new format is as simple as creating a new Symfony Normalizer for it Built-in formats: JSON-LD, HAL, XML, YAML, CSV, JSON, HTML (UI) To retrieve a resource in a given format: add an Accept HTTP header or use the format name as file extension
  • 96. The Schema Generator Pick an existing data model from (resources and properties) from schema.org: $ docker-compose exec php vendor/bin/schema generate-types src/ schema.yml
  • 98. The Schema Generator PHP classes, properties, getters and setters (PSR compliant) Doctrine ORM mapping (including relations and mapped superclasses) Validation constraints Full PHPDoc extracted from schema human-readable descriptions Mapping with schema.org's IRIs The generator uses schema.org data to automatically bootstrap: Relations between classes (supported by the API system too)
  • 99. Rate this talk: Follow me: @dunglas joind.in/talk/7abdc