3. What is Symfony?
16/03/2016 Make with ♥ by Studeal 3
« Symfony is a set of PHP Components, a
Web Application framework, a Philosophy, and
a Community — all working together in
harmony. »
4. What is Symfony? / Inside & Bundles
« Symfony is also an HTTP full-
stack web framework made of
bundles and third party libraries »
16/03/2016 Make with ♥ by Studeal 4
Dependency Injection
Locale
EventDispatcher
Console
Routing
HttpKernel
Yaml
FOSUserBundle
FOSRestBundle
KnpPaginatorBundle
5. 16/03/2016 Make with ♥ by Studeal 5
What is Symfony? / The Power
Oui oui vous ne rêvez pas …
+2,500
Bundles
+300,000
Symfony developers
+5,000,000
Monthly downloads
+2,000
Project contributors
Official Documentation
6. REST API / The Basics
API
« Application Programming
Interface »
16/03/2016 Make with ♥ by Studeal 6
REST
« REpresentational State
Transfer »
RESTful API
8. REST & Symfony2 / Structure
• MVC
• API REST HTTP with Symfony2 (RESTful API)
• ToDo application: list, create, update, delete notes
• Relation avec base de données
• JSON
16/03/2016 Make with ♥ by Studeal 8
9. REST & Symfony2 / Bundles (1)
• View (JSON)
• REST Routes (GET /notes, POST /notes…)
• Custom Headers (ex: authentification, format ...)
• RESTful decoding HTTP request
• HTTP codes
16/03/2016 Make with ♥ by Studeal 9
https://github.com/FriendsOfSymfony/FOSRestBundle
FOSRestBundle
10. REST & Symfony2 / Bundles (2)
• Serialization (Deserialization)
• Security
• Custom exposition
16/03/2016 Make with ♥ by Studeal 10
https://github.com/schmittjoh/JMSSerializerBundle
+ https://github.com/schmittjoh/JMSSecurityExtraBundle
JMSSerializerBundle + JMSSecurityExtraBundle
11. REST & Symfony2 / Bundles (3)
• API Documentation
• Sandbox
• Tests
• CORS (Cross-Origin Resource Sharing)
16/03/2016 Make with ♥ by Studeal 11
https://github.com/nelmio/NelmioApiDocBundle
+ https://github.com/nelmio/NelmioCorsBundle
NelmioApiDocBundle + NelmioCorsBundle
12. REST & Symfony2 / Bundles
(summary)
• https://github.com/FriendsOfSymfony/FOSRestBundle
• https://github.com/schmittjoh/JMSSerializerBundle
• https://github.com/nelmio/NelmioApiDocBundle
• #Bonus: https://github.com/nelmio/NelmioCorsBundle
• #Bonus: https://github.com/schmittjoh/JMSSecurityExtraBundle
16/03/2016 Make with ♥ by Studeal 12
Utilisation API REST Symfony2 en prod avec client AngularJS
Studeal : 3 usages, 3 utilisateurs
Symfony2 is a set of reusable, standalone, decoupled, and cohesive PHP components that solve common web development problems.
A « Bundle » is a directory containing a set of files that implement a single feature and can be shared with the Community
Symfony is an HTTP framework that converts a Request object into a Response object.
API
Web service ici avec ensemble de fonctions afin de faciliter la consommation d’une bdd par exemple par un autre logiciel
REST
REST est un style d'architecture pour les systèmes hypermédia distribués, créé par Roy Fielding en 2000, qui propose l'exposition de ressources
Routes, urls auto desscriptives (endpoints)
Contraintes:
Client–server + scalable
Stateless
Cacheable
Uniform interface (JSON, XML, HTML)
HATEOAS (Hypermedia as the engine of application state)
Applied to web service:
Verbes HTTP : GET, POST, PATCH, PUT, DELETE …
Base URI
Internet media type, JSON
Hypertext links, HATEOAS
REST API = Application web proposant un ou plusieurs Web Services respectant le formalise REST (RESTful APIs)