Upgrade to Pro — share decks privately, control downloads, hide ads and more …

API Platform version 2

API Platform version 2

Discover API Platform v2, a framework to create easily API-first applications.

Kévin Dunglas

May 17, 2016
Tweet

More Decks by Kévin Dunglas

Other Decks in Programming

Transcript

  1. ABOUT ME KÉVIN DUNGLAS ▸ Founder of Les-Tilleuls.coop ▸ Symfony

    Core Team Member ▸ API Platform Creator ▸ Teacher at Lille 1 University Twitter / GitHub : @dunglas dunglas.fr
  2. ABOUT US LES-TILLEULS.COOP ▸ 15+ consultants and developers ▸ Symfony

    / Angular 1 & 2 / React / Amazon AWS / Docker / SCRUM / … ▸ 100% owned by his employees ▸ 1 person = 1 vote, all benefits are equally distributed ▸ We are hiring! Twitter / GitHub : @coopTilleuls les-tilleuls.coop
  3. WHAT IS API PLATFORM? THE GOALS OF THE FRAMEWORK ▸

    Create web APIs easily (focused on Developer eXperience) ▸ Develop a fully-featured API in minutes ▸ Override and customize everything you need ▸ Be compliant out of the box with the last generation of standards and usages ▸ Linked Data, HATEOAS and semantic web support : JSON-LD, Hydra, schema.org, JWT…
  4. ARCHITECTURE, PATTERNS, PHILOSOPHY, BENEFITS AND (THE BUNCH OF) EXISTING FEATURES:

    DUNGLAS.FR/SLIDES/FORUM-PHP-2015/ ACCURATE FOR V1 AND 2!
  5. WHAT IS API PLATFORM? ROADMAP ▸ API Platform v1.1 ▸

    Released yesterday (2016-05-16) ▸ Bug fix and security only (no more new features) ▸ Shipped with Symfony 2.8, compatible with SF 3.0 ▸ End Of Life: Nov 2019 (= EOL of SF 2.8) ▸ API Platform v2.0 alpha 1 ▸ Released yesterday ▸ stable release: June (SF 3.1 release: May)
  6. WHAT IS API PLATFORM? FACT CHECKING ▸ First stable release:

    September 18, 2015 ▸ 660+ stars on GitHub ▸ 900+ commits ▸ 5 Core Team Members: Samuel Roze (Inviqa), Teoh Han Hui (Tripviss), Théo Fidry (Haircvt), Vincent Chalamon (Les-Tilleuls.coop) and me ▸ 60+ awesome contributors including Antoine Bluchet, Maxime Steinhausser, Hamza Amrouche, Jérémy Derussé and Charles Sarazin… ▸ Adopted by: Sensiolabs, Smile, The Fork/TripAdvisor, BeIN Sports, Tripviss, Eaux du Nord, Le Parti de Gauche, ExaqtWorld, Ville de Roubaix… And recently by some new major companies (announcement soon).
  7. DISCOVERING API PLATFORM 2.0 ARCHITECTURAL CHANGES ▸ Not a full

    rewrite: fix design limitations from v1 - but contains BC breaks! ▸ « API Platform Core » (formerly DunglasApiBundle) is not a Symfony bundle anymore but a standalone PHP library built with SF components ▸ Usable in raw PHP (Laravel support is coming) ▸ Symfony still the first-class citizen (bundle included) ▸ Implements the Action-Domain-Responder pattern using events of the Symfony kernel (more flexible, easier to customize) ▸ PHP 7+: use new features such as the ?? operator, scalar type hints and return types ▸ Symfony 3.1+: a lof of code from v1 have been moved to SF components: Serializer, PropertyInfo, PropertyAccess
  8. CORE: NEW FILTERS CONFIGURATION AVAILABLE FILTERS (DOCTRINE) ▸ Search (LIKE

    %%) ▸ Order (sorting) ▸ Date ▸ Range ▸ Boolean ▸ Numeric
  9. CORE: OPERATIONS AND SERIALIZATION GROUPS WHAT HAPPENS? ▸ Only GET

    /tasks and GET /tasks/{id} are available ▸ All other operations (POST, PUT, DELETE) are not registered ▸ When using the configuration, declaration must be explicits ▸ Different serialization groups are applied per operation ▸ Only « text » is displayed in the list ▸ « text » and « status » are displayed for the item IRI ▸ Deserialization isn’t impacted (use the denormalization_context key) ▸ Works with XML and YAML mappings too
  10. CORE: A NEW EVENT SYSTEM A NEW EVENT SYSTEM ▸

    The event system of v1 has been removed (PRE_CREATE, POST_CREATE, PRE_VALIDATE…) ▸ V2 now relies on Symfony HttpKernel events ▸ V2 implements the Action-Domain-Responder pattern ▸ Events listeners (see next slide) are only applied on request handled by API Platform (not on standard Symfony requests) ▸ Use kernel events to hook your custom logic: security (isGranted), cache headers, validation, persistence, call to external APIs, mail…
  11. CORE: A NEW EVENT SYSTEM THE REQUEST FLOW ▸ kernel.request:

    guess the best response format (content negotiation) ▸ controller: retrieve the data from the persistence system (GET, PUT, DELETE) ▸ controller: deserialize the request (POST, PUT) ▸ controller: return an entity (GET, POST, PUT, DELETE), an array of entities or a pagination (cGET) ▸ kernel.view (priority 20): validate data (POST, PUT) ▸ kernel.view (priority 10): persist data (POST, PUT, DELETE) ▸ kernel.view (priority 0): serialize data and transform them in a Response
  12. CORE: CUSTOM OPERATIONS AND CONTROLLERS WHY USING CUSTOM OPERATIONS AND

    CONTROLLERS? ▸ Create service-oriented (or non-REST) endpoints ▸ Customize URLs ▸ Manage sub-resources (ex: /tasks/{id}/comments/{c_id}) ▸ Hook your own logic when kernel events are not enough ▸ Always prefer kernel events when possible!
  13. CORE: CUSTOM OPERATIONS AND CONTROLLERS OTHER EXTENSION POINTS (EXIST IN

    V1) ▸ Filters: manipulate the HTTP request and Doctrine (if used) queries (filtering, sorting…) ▸ Data Providers: retrieve data from the persistence layer ▸ Normalizers (Symfony Serializer) ▸ Encoders (Symfony Serializer) ▸ Validators (Symfony Validation) ▸ All Symfony (services, config…) and Doctrine (if used) extension points
  14. CORE: CONTENT NEGOTIATION CORE: CONTENT NEGOTIATION ▸ Select the best

    format to use depending of the HTTP Accept header ▸ Built on top of William Durand’s Negotiation 2 library (same as FOSRest) ▸ Hooks into the Symfony Serializer component ▸ Allows to return hypermedia (HAL, JSON-API…) and non hypermedia (raw JSON, raw XML…) formats
  15. SCHEMA GENERATOR: NEW FEATURES ALSO IN SCHEMA GENERATOR 1.1 ▸

    The v1.1 of the Schema Generator is included in API Platform v1.1 and v2 ▸ Available as PHAR ▸ MongoDB support ▸ Symfony v3 compatibility ▸ Doctrine Embeddable support ▸ Support custom properties and entities ▸ Can leverage any RDF(a) vocabulary (lov.okfn.org) ▸ Serialization groups support ▸ Doctrine: unique, nullable and @Column can be customized
  16. CORE: NEW CONFIGURATION SYSTEM MORE NEW API PLATFORM FEATURES ▸

    MongoDB support (WIP) ▸ Pagination (configurable - new Hydra format) ▸ Relation handling ▸ New filters ▸ Complex type serialization (ex: nested objects) ▸ PSR-6 support (performance)
  17. WHAT’S NEW WITH API PLATFORM 2? CORE NEW IN THE

    SYMFONY SERIALIZER COMPONENT 3.1 ▸ data: URI to SplFileInfo normalizer for file upload ▸ \DateTime normalizer ▸ Nested object serialization ▸ Tree serialization with the @MaxDepth annotation ▸ Performance improvements ▸ PSR-6 support (performance)
  18. DISCOVERING API PLATFORM 2.0 YOU CAN HELP US! ▸ Finish

    and improve the doc: api-platform/doc#37 ▸ Finish MongoDB support: api-platform/core#461 ▸ Test, test and test again ▸ Improve the website: github.com/api-platform/website ▸ Spread the word!
  19. DISCOVERING API PLATFORM 2.0 WHAT’S NEXT (2.1, 2.2…) ▸ Client-side

    tools ▸ [alpha] ng-admin / Hydra bridge: github.com/api-platform/admin ▸ [WIP] Angular 2 Hydra admin: github.com/Gregcop1/hydra-admin ▸ [todo] Guzzle integration ▸ [todo] React / Angular 2 / Vue.js / … CRUD generators using the Hydra doc ▸ [todo] HAL and JSONAPI support (easy pick, thanks to the new architecture) ▸ [todo] Swagger 2.0 support (another easy pick)