SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
Réaliser des applications
innovantes avec Symfony2
Symfony2, API REST et Javascript
Qui sommes-nous ?
Alexandre Salomé
Consultant
@alexandresalome
Kévin Dunglas
Co-fondateur
@dunglas
Architecture
API REST
- Exposer les données de l’application
- HTTP + JSON/XML
- Plus léger que SOAP (adapté pour le mobile)
- RESTful
curl -X POST http://example.com/api/user
--data '{"username": "alice", "fullname": "Alice"}'
SPA (Single Page Application)
- Application JavaScript
- S’exécute côté client
- Récupère et modifie les données via l’API
REST
- Seules les données utiles transitent
Application
apps
mobiles
site web
responsive
autres applications et
sites
(ERP, logistique,
partenaires…)
application
Facebook
API REST
Internet
Stockage de données
Application Serveur Web
Internet
Applications tierces
Fichiers
Ecosystème
- PHP 5.3, 5.4, 5.5 (namespaces, traits)
- Composer
- Frameworks / CMS / PSR (PHP-FIG)
- PHPUnit / phpspec / Behat
PHP-FIG : http://www.php-fig.org
Awesome PHP : https://github.com/ziadoz/awesome-php
PHP
- Framework “full stack”
- Découplé en composants
- Axé fiabilité (tests), sécurité et performance
- Design moderne (POO, MVC, DIC, Events…)
- Intègre des bibliothèques tierces reconnues :
Twig, Swiftmailer, Doctrine
http://symfony.com / http://github.com/symfony/symfony
Symfony2
AngularJS
- Framework JavaScript MVC complet
- Maintenu par Google
- Communauté importante
- S’intègre parfaitement avec Symfony
http://angularjs.org/
Backbone.js
- Bibliothèque JavaScript
- Synchronise la couche modèle de l’application
cliente avec une API REST
- S’intègre facilement dans du code JS existant
- S’intègre parfaitement avec Symfony
http://backbonejs.org/
Alternatives
- Ember.js :
http://emberjs.com/
- Chaplin.js :
http://chaplinjs.org/
Et bien d’autres.
Implémentation
Modèle relationnel objet
- Doctrine : http://www.doctrine-project.org/
(ORM + ODM + O*M)
- Propel : http://propelorm.org/
- PHPCR : http://phpcr.github.io/
- ElasticSearch : http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/
Voir aussi https://github.com/ziadoz/awesome-php#orm-and-datamapping
Sérialisation des objets
return new JsonResponse($object->toArray());
Composant Serializer
http://symfony.com/fr/doc/current/components/serializer.html
JMSSerializerBundle
https://github.com/schmittjoh/JMSSerializerBundle
Exposer une API REST
- FOSRestBundle :
https://github.com/FriendsOfSymfony/FOSRestBundle
- NelmioApiDocBundle :
https://github.com/nelmio/NelmioApiDocBundle
- JMSSerializerBundle :
http://jmsyst.com/bundles/JMSSerializerBundle
Envoyer des données
- “Désérialisation” du JSON ou du XML :
JMSSerializerBundle
- Validation des données et mise à jour des
objets :
Symfony Form framework
Gestion des assets
- Less, SASS
- Minify, Uglify, YUI Compressor, …
- Bower
Avec Symfony : Assetic
Sans Symfony : Grunt + Yeoman
Show me the code
Exemple KISS
/**
* @Route(path="/user/{id}", name="user_show")
*/
public function showAction($id)
{
$user = $this
->getDoctrine()
->getRepository('AcmeDemoBundle:User')
->find($id)
;
if (!$user) {
throw $this->createNotFoundException(sprintf('User %s not found.', $id));
}
return new JsonResponse($user->toArray());
}
Exemple (encore plus court)
/**
* @Route(path="/user/{id}", name="user_show")
*/
public function showAction(User $user)
{
return new JsonResponse($user->toArray());
}
Behat-Launcher
Côté serveur (80%)
- Silex
- Composant
Serializer
Côté client (20%)
- Twitter Bootstrap
- AngularJS
- Internationalisation
- Grunthttp://github.com/alexandresalome/behat-launcher
DunglasTodoMVCBundle
Côté serveur (50%)
- Symfony
- FOSRest / JMSSerializer
Côté client (50%)
- Backbone.js et Chaplin.js
- CoffeeScript
http://github.com/dunglas/DunglasTodoMVCBundle
Aller plus loin
Référencement
- Google ne sait pas exécuter le JavaScript
- Les SPA ne sont pas référencées par défaut
Solution : Prerender.io (snapshots)
http://prerender.io
https://github.com/rjanot/YuccaPrerenderBundle
Sécurité
- Protection CSRF d’une SPA
https://github.com/dunglas/DunglasAngularCsrfBundle
- Utilisation de l’objet JsonResponse
JSON Vulnerability
Hypermedia API
Découverte dynamique des serveurs par les
clients :
- HATEOAS (HAL+JSON)
http://hateoas-php.org/
- Hydra / JSON-LD http://www.markus-
lanthaler.com/hydra/
Des questions ?
Une bière !

Weitere ähnliche Inhalte

Ähnlich wie Diaporama du sfPot Lillois du 20 mars 2014

Communications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHPCommunications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHPjulien pauli
 
Soutenance Zend Framework vs Symfony
Soutenance Zend Framework vs SymfonySoutenance Zend Framework vs Symfony
Soutenance Zend Framework vs SymfonyVincent Composieux
 
Réu technodejs
Réu technodejsRéu technodejs
Réu technodejsnaholyr
 
Une API REST vite fait bien fait avec API-Platform 2
Une API REST vite fait bien fait avec API-Platform 2Une API REST vite fait bien fait avec API-Platform 2
Une API REST vite fait bien fait avec API-Platform 2Guilhem Bourgoin
 
Symfony2 & l'architecture Rest
Symfony2 & l'architecture Rest Symfony2 & l'architecture Rest
Symfony2 & l'architecture Rest Ahmed Ghali
 
Présentation de ElasticSearch / Digital apéro du 12/11/2014
Présentation de ElasticSearch / Digital apéro du 12/11/2014Présentation de ElasticSearch / Digital apéro du 12/11/2014
Présentation de ElasticSearch / Digital apéro du 12/11/2014Silicon Comté
 
Asp.Net Web.API, SignalR et UX : le futur
Asp.Net Web.API, SignalR et UX : le futurAsp.Net Web.API, SignalR et UX : le futur
Asp.Net Web.API, SignalR et UX : le futurMicrosoft
 
Enrichir vos contenus Wordpress avec les API - WPTech 2015
Enrichir vos contenus Wordpress avec les API - WPTech 2015Enrichir vos contenus Wordpress avec les API - WPTech 2015
Enrichir vos contenus Wordpress avec les API - WPTech 2015PXNetwork
 
ÉVolution d'un système de publication de données techniques automobiles, modé...
ÉVolution d'un système de publication de données techniques automobiles, modé...ÉVolution d'un système de publication de données techniques automobiles, modé...
ÉVolution d'un système de publication de données techniques automobiles, modé...SemWebPro
 
xml-webservices-intro.pdfhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
xml-webservices-intro.pdfhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhxml-webservices-intro.pdfhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
xml-webservices-intro.pdfhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhindguendouz2000
 
Web dev open door
Web dev   open doorWeb dev   open door
Web dev open doorLeTesteur
 
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...Jean-Laurent de Morlhon
 
Créer une API GraphQL avec Symfony
Créer une API GraphQL avec SymfonyCréer une API GraphQL avec Symfony
Créer une API GraphQL avec SymfonySébastien Rosset
 
Cours services web_fabrice_mourlin
Cours services web_fabrice_mourlinCours services web_fabrice_mourlin
Cours services web_fabrice_mourlinangeeLee
 
Votre première App SharePoint pour Office 365 avec Visual Studio !
Votre première App SharePoint pour Office 365 avec Visual Studio !Votre première App SharePoint pour Office 365 avec Visual Studio !
Votre première App SharePoint pour Office 365 avec Visual Studio !Gilles Pommier
 

Ähnlich wie Diaporama du sfPot Lillois du 20 mars 2014 (20)

Communications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHPCommunications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHP
 
Soutenance Zend Framework vs Symfony
Soutenance Zend Framework vs SymfonySoutenance Zend Framework vs Symfony
Soutenance Zend Framework vs Symfony
 
Réu technodejs
Réu technodejsRéu technodejs
Réu technodejs
 
Une API REST vite fait bien fait avec API-Platform 2
Une API REST vite fait bien fait avec API-Platform 2Une API REST vite fait bien fait avec API-Platform 2
Une API REST vite fait bien fait avec API-Platform 2
 
Symfony2 & l'architecture Rest
Symfony2 & l'architecture Rest Symfony2 & l'architecture Rest
Symfony2 & l'architecture Rest
 
Présentation de ElasticSearch / Digital apéro du 12/11/2014
Présentation de ElasticSearch / Digital apéro du 12/11/2014Présentation de ElasticSearch / Digital apéro du 12/11/2014
Présentation de ElasticSearch / Digital apéro du 12/11/2014
 
Asp.Net Web.API, SignalR et UX : le futur
Asp.Net Web.API, SignalR et UX : le futurAsp.Net Web.API, SignalR et UX : le futur
Asp.Net Web.API, SignalR et UX : le futur
 
Enrichir vos contenus Wordpress avec les API - WPTech 2015
Enrichir vos contenus Wordpress avec les API - WPTech 2015Enrichir vos contenus Wordpress avec les API - WPTech 2015
Enrichir vos contenus Wordpress avec les API - WPTech 2015
 
ÉVolution d'un système de publication de données techniques automobiles, modé...
ÉVolution d'un système de publication de données techniques automobiles, modé...ÉVolution d'un système de publication de données techniques automobiles, modé...
ÉVolution d'un système de publication de données techniques automobiles, modé...
 
xml-webservices-intro.pdfhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
xml-webservices-intro.pdfhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhxml-webservices-intro.pdfhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
xml-webservices-intro.pdfhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
 
Presentation tz2018
Presentation tz2018Presentation tz2018
Presentation tz2018
 
Web dev open door
Web dev   open doorWeb dev   open door
Web dev open door
 
Web Service API Odoo - android
Web Service API Odoo - androidWeb Service API Odoo - android
Web Service API Odoo - android
 
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
Ou sont mes beans, contrats et workflows ? WOA et REST: Un changement de ment...
 
Lp web tp3_idse
Lp web tp3_idseLp web tp3_idse
Lp web tp3_idse
 
Créer une API GraphQL avec Symfony
Créer une API GraphQL avec SymfonyCréer une API GraphQL avec Symfony
Créer une API GraphQL avec Symfony
 
Cours services web_fabrice_mourlin
Cours services web_fabrice_mourlinCours services web_fabrice_mourlin
Cours services web_fabrice_mourlin
 
Support Web Services SOAP et RESTful Mr YOUSSFI
Support Web Services SOAP et RESTful Mr YOUSSFISupport Web Services SOAP et RESTful Mr YOUSSFI
Support Web Services SOAP et RESTful Mr YOUSSFI
 
Votre première App SharePoint pour Office 365 avec Visual Studio !
Votre première App SharePoint pour Office 365 avec Visual Studio !Votre première App SharePoint pour Office 365 avec Visual Studio !
Votre première App SharePoint pour Office 365 avec Visual Studio !
 
12-Factor
12-Factor12-Factor
12-Factor
 

Mehr von 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, PantherLes-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 browsersLes-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 ProjectsLes-Tilleuls.coop
 
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 ProjectsLes-Tilleuls.coop
 
API Platform: Full Stack Framework Resurrection
API Platform: Full Stack Framework ResurrectionAPI Platform: Full Stack Framework Resurrection
API Platform: Full Stack Framework ResurrectionLes-Tilleuls.coop
 
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)Les-Tilleuls.coop
 
Symfony 2 : Performances et Optimisations
Symfony 2 : Performances et OptimisationsSymfony 2 : Performances et Optimisations
Symfony 2 : Performances et OptimisationsLes-Tilleuls.coop
 
Atelier #3 intégration html
Atelier #3 intégration htmlAtelier #3 intégration html
Atelier #3 intégration htmlLes-Tilleuls.coop
 
Atelier #2 initiation à css
Atelier #2 initiation à cssAtelier #2 initiation à css
Atelier #2 initiation à cssLes-Tilleuls.coop
 

Mehr von Les-Tilleuls.coop (13)

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
 
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
 
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
 
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)
 
Symfony 2 : Performances et Optimisations
Symfony 2 : Performances et OptimisationsSymfony 2 : Performances et Optimisations
Symfony 2 : Performances et Optimisations
 
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
 

Diaporama du sfPot Lillois du 20 mars 2014

  • 1. Réaliser des applications innovantes avec Symfony2 Symfony2, API REST et Javascript
  • 2. Qui sommes-nous ? Alexandre Salomé Consultant @alexandresalome Kévin Dunglas Co-fondateur @dunglas
  • 4. API REST - Exposer les données de l’application - HTTP + JSON/XML - Plus léger que SOAP (adapté pour le mobile) - RESTful curl -X POST http://example.com/api/user --data '{"username": "alice", "fullname": "Alice"}'
  • 5. SPA (Single Page Application) - Application JavaScript - S’exécute côté client - Récupère et modifie les données via l’API REST - Seules les données utiles transitent
  • 6. Application apps mobiles site web responsive autres applications et sites (ERP, logistique, partenaires…) application Facebook API REST Internet
  • 7. Stockage de données Application Serveur Web Internet Applications tierces Fichiers
  • 9. - PHP 5.3, 5.4, 5.5 (namespaces, traits) - Composer - Frameworks / CMS / PSR (PHP-FIG) - PHPUnit / phpspec / Behat PHP-FIG : http://www.php-fig.org Awesome PHP : https://github.com/ziadoz/awesome-php PHP
  • 10. - Framework “full stack” - Découplé en composants - Axé fiabilité (tests), sécurité et performance - Design moderne (POO, MVC, DIC, Events…) - Intègre des bibliothèques tierces reconnues : Twig, Swiftmailer, Doctrine http://symfony.com / http://github.com/symfony/symfony Symfony2
  • 11. AngularJS - Framework JavaScript MVC complet - Maintenu par Google - Communauté importante - S’intègre parfaitement avec Symfony http://angularjs.org/
  • 12. Backbone.js - Bibliothèque JavaScript - Synchronise la couche modèle de l’application cliente avec une API REST - S’intègre facilement dans du code JS existant - S’intègre parfaitement avec Symfony http://backbonejs.org/
  • 13. Alternatives - Ember.js : http://emberjs.com/ - Chaplin.js : http://chaplinjs.org/ Et bien d’autres.
  • 15. Modèle relationnel objet - Doctrine : http://www.doctrine-project.org/ (ORM + ODM + O*M) - Propel : http://propelorm.org/ - PHPCR : http://phpcr.github.io/ - ElasticSearch : http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/ Voir aussi https://github.com/ziadoz/awesome-php#orm-and-datamapping
  • 16. Sérialisation des objets return new JsonResponse($object->toArray()); Composant Serializer http://symfony.com/fr/doc/current/components/serializer.html JMSSerializerBundle https://github.com/schmittjoh/JMSSerializerBundle
  • 17. Exposer une API REST - FOSRestBundle : https://github.com/FriendsOfSymfony/FOSRestBundle - NelmioApiDocBundle : https://github.com/nelmio/NelmioApiDocBundle - JMSSerializerBundle : http://jmsyst.com/bundles/JMSSerializerBundle
  • 18. Envoyer des données - “Désérialisation” du JSON ou du XML : JMSSerializerBundle - Validation des données et mise à jour des objets : Symfony Form framework
  • 19. Gestion des assets - Less, SASS - Minify, Uglify, YUI Compressor, … - Bower Avec Symfony : Assetic Sans Symfony : Grunt + Yeoman
  • 20. Show me the code
  • 21. Exemple KISS /** * @Route(path="/user/{id}", name="user_show") */ public function showAction($id) { $user = $this ->getDoctrine() ->getRepository('AcmeDemoBundle:User') ->find($id) ; if (!$user) { throw $this->createNotFoundException(sprintf('User %s not found.', $id)); } return new JsonResponse($user->toArray()); }
  • 22. Exemple (encore plus court) /** * @Route(path="/user/{id}", name="user_show") */ public function showAction(User $user) { return new JsonResponse($user->toArray()); }
  • 23. Behat-Launcher Côté serveur (80%) - Silex - Composant Serializer Côté client (20%) - Twitter Bootstrap - AngularJS - Internationalisation - Grunthttp://github.com/alexandresalome/behat-launcher
  • 24. DunglasTodoMVCBundle Côté serveur (50%) - Symfony - FOSRest / JMSSerializer Côté client (50%) - Backbone.js et Chaplin.js - CoffeeScript http://github.com/dunglas/DunglasTodoMVCBundle
  • 26. Référencement - Google ne sait pas exécuter le JavaScript - Les SPA ne sont pas référencées par défaut Solution : Prerender.io (snapshots) http://prerender.io https://github.com/rjanot/YuccaPrerenderBundle
  • 27. Sécurité - Protection CSRF d’une SPA https://github.com/dunglas/DunglasAngularCsrfBundle - Utilisation de l’objet JsonResponse JSON Vulnerability
  • 28. Hypermedia API Découverte dynamique des serveurs par les clients : - HATEOAS (HAL+JSON) http://hateoas-php.org/ - Hydra / JSON-LD http://www.markus- lanthaler.com/hydra/