SlideShare uma empresa Scribd logo
1 de 99
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

Best Practices in Web Service Design
Best Practices in Web Service DesignBest Practices in Web Service Design
Best Practices in Web Service Design
Lorna Mitchell
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
habib_786
 
Présentation de RMI Java
Présentation de RMI JavaPrésentation de RMI Java
Présentation de RMI Java
Zakaria Bouazza
 
Content Management With Apache Jackrabbit
Content Management With Apache JackrabbitContent Management With Apache Jackrabbit
Content Management With Apache Jackrabbit
Jukka Zitting
 

Mais procurados (20)

Best Practices in Web Service Design
Best Practices in Web Service DesignBest Practices in Web Service Design
Best Practices in Web Service Design
 
24 Sitecore Tips that Every Sitecore Architect Needs to Know
24 Sitecore Tips that Every Sitecore Architect Needs to Know24 Sitecore Tips that Every Sitecore Architect Needs to Know
24 Sitecore Tips that Every Sitecore Architect Needs to Know
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
What is API - Understanding API Simplified
What is API - Understanding API SimplifiedWhat is API - Understanding API Simplified
What is API - Understanding API Simplified
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Strapi Meetup Presentation
Strapi Meetup PresentationStrapi Meetup Presentation
Strapi Meetup Presentation
 
ASP.NET Web API
ASP.NET Web APIASP.NET Web API
ASP.NET Web API
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
Deploying a website
Deploying a websiteDeploying a website
Deploying a website
 
Présentation de RMI Java
Présentation de RMI JavaPrésentation de RMI Java
Présentation de RMI Java
 
Web api
Web apiWeb api
Web api
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple Steps
 
Rest API
Rest APIRest API
Rest API
 
REST-API overview / concepts
REST-API overview / conceptsREST-API overview / concepts
REST-API overview / concepts
 
Web services SOAP et REST
Web services  SOAP et RESTWeb services  SOAP et REST
Web services SOAP et REST
 
Simple présentation de Wordpress
Simple présentation de WordpressSimple présentation de Wordpress
Simple présentation de Wordpress
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | Edureka
 
Content Management With Apache Jackrabbit
Content Management With Apache JackrabbitContent Management With Apache Jackrabbit
Content Management With Apache Jackrabbit
 
Spring Cloud Function: Where We Were, Where We Are, and Where We’re Going
Spring Cloud Function: Where We Were, Where We Are, and Where We’re GoingSpring Cloud Function: Where We Were, Where We Are, and Where We’re Going
Spring Cloud Function: Where We Were, Where We Are, and Where We’re Going
 
MongoDB 101
MongoDB 101MongoDB 101
MongoDB 101
 

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

UIT: Our Skills
UIT: Our SkillsUIT: Our Skills
UIT: Our Skills
uitpramati
 
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
Phi Jack
 
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
 

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
imonikaupta
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
Diya Sharma
 

Último (20)

'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 

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