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

Discovering API Platform v2 (updated version)

Discovering API Platform v2 (updated version)

Slides about the API Platform framework presented at the first "Apero PHP" in Amiens, France.

https://les-tilleuls.coop/fr/blog/article/save-the-date-1er-apero-php-a-amiens

Kévin Dunglas

July 07, 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. 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
  6. CORE: NEW FILTERS CONFIGURATION AVAILABLE FILTERS (DOCTRINE) ▸ Search (LIKE

    %%) ▸ Order (sorting) ▸ Date ▸ Range ▸ Boolean ▸ Numeric
  7. 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
  8. 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) ▸ Event listeners are autoregistered and autowired (using DunglasActionBundle) ▸ Use kernel events to hook your custom logic: security (isGranted), cache headers, validation, persistence, call to external APIs, mail…
  9. 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 ▸ Controllers and actions are autoregistered and autowired (DunglasActionBundle) ▸ Always prefer kernel events when possible!
  10. 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
  11. CORE: CONTENT NEGOTIATION CORE: CONTENT NEGOTIATION ▸ Select the best

    format to use depending of the HTTP Accept header ▸ Built-in support for JSON-LD, XML, JSON and CSV ▸ 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
  12. CORE: NEW CONFIGURATION SYSTEM MORE NEW API PLATFORM FEATURES ▸

    Swagger 2.0 support ▸ Configurable Pagination ▸ Relation handling ▸ Some new filters ▸ Complex type serialization (ex: nested objects) ▸ PSR-6 cache support (performance)
  13. WHAT’S NEW WITH API PLATFORM 2? CORE NEW IN THE

    SYMFONY SERIALIZER COMPONENT 3.1/3.2 ▸ data: URI to SplFileInfo normalizer for file upload ▸ \DateTime normalizer ▸ Nested object serialization ▸ Tree serialization with the @MaxDepth annotation ▸ CSV support ▸ Performance improvements ▸ PSR-6 support (performance)
  14. 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!
  15. 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/coopTilleuls/hm-admin ▸ [todo] Guzzle integration trough Jane (JoliCode) ▸ [todo] React / Angular 2 / Vue.js / … CRUD generators using the Hydra doc ▸ [todo] HAL and JSONAPI support (easy pick, thanks to the new architecture)