$30 off During Our Annual Pro Sale. View Details »

API Platform 3

API Platform 3

What's new in API Platform 3?

Kévin Dunglas

September 15, 2022
Tweet

More Decks by Kévin Dunglas

Other Decks in Programming

Transcript

  1. The API-First Framework
    Gets New Superpowers

    View Slide

  2. About me
    ✔ API Platform creator
    ✔ Les-Tilleuls.coop founder
    Kévin Dunglas
    @dunglas
    dunglas.fr

    View Slide

  3. Improved Developer eXperience
    01
    02
    03
    04
    Re-Engineered Design
    Standalone Client Tools
    New Roadmap

    View Slide

  4. But… Where Is API Platform 3?!

    View Slide

  5. Antoine Bluchet
    aka soyuka
    ✔ API Platform 3 lead
    ✔ Long-time Core Team member
    ✔ Famous FOSS contributor
    ○ pm2 maintainer
    ○ JS, PHP, Go…

    View Slide

  6. View Slide

  7. Let’s Release It Now!
    ✔ Test, fix, test 🔁
    ✔ Write docs and changelogs
    ✔ Write blog posts
    ✔ Tag 10th of packages
    ✔ Update the distribution

    View Slide

  8. View Slide

  9. Let’s Celebrate
    API Platform
    Release Party
    6pm @ Les Sales Mômes

    View Slide

  10. View Slide

  11. 01 - Re-Engineered
    Design

    View Slide

  12. API Platform
    Core Values
    ✔ Easy to use…
    - Rapid Application Development
    ✔ …but suitable for advanced use cases
    - DDD, Clean Architecture, microservices…
    ✔ Batteries included
    ✔ Fast, cheap, and green
    ✔ Standards-compliant

    View Slide

  13. Pain Points With v2
    ✔ “Subresources” (e.g. /organization/1/users/22)
    - Read-only
    - hard to customize
    ✓ Having small resources linked together instead of big resources improve
    performance and cache dynamics, cf. my Edge Side APIs presentation
    ✔ Hooking custom logic
    - possible but not trivial, not well understood
    ✓ DDD, Clean Architecture and custom persistence should be intuitive and easy
    ✔ Configuration
    - Verbose and hard to read
    ✓ Leverage PHP 8 attributes 😻

    View Slide

  14. Opportunities for v3
    ✔ Fix design issues
    ✔ Leverage new features of our stack
    ○ Improved PHP attributes and types
    ○ Symfony, Docker, Next.js, Caddy…
    ✔ Rely even more on standards
    ○ RDF
    ○ OpenAPI
    ✔ Reduce maintenance burden
    ○ Remove legacy code

    View Slide

  15. Back to The Basics:
    The Web Architecture
    ✔ Webapps expose a network of resources
    ✔ Resources:
    - Any information that can be named
    - Valid resources: a thing, a temporary service,
    a collection of resources
    ✔ Resources have representations:
    - Ex: JSON-LD, JPEG, CSV…
    - The same resource can have multiple
    representations
    REST

    View Slide

  16. Interesting Standards
    Resource Description Format (RDF)
    ✔ Data model for web resources
    ✔ Various serialization formats:
    JSON-LD, Turtle, XML-RDF, RDFa…
    ✔ Classes, properties, links, type system…
    RDF

    View Slide

  17. Interesting Standards
    Uniform Resource Identifiers (URI):
    ✔ ID system for web resources
    ✔ https:/
    /example.com/organizations/22/us
    ers/42
    URI

    View Slide

  18. Interesting Standards
    URI Template:
    ✔ URI that includes parameters to be
    substituted
    ✔ https:/
    /example.com/organizations/{oID}
    /users/{uID}
    URI Template

    View Slide

  19. Resource-Oriented
    Framework
    DEFINE THE RESOURCES
    TO EXPOSE

    View Slide

  20. PHP As an API Specification
    Language
    ✔ Describe the public data model
    exposed by the API
    ✔ Leverage the expressivity of PHP:
    - Types, visibility, relations,
    attributes…
    ✔ Resource objects are DTOs

    View Slide

  21. Resource-Oriented Framework
    ✔ Provides the infrastructure layer
    of your API
    ✔ Serializes resources
    representations from PHP objects
    ✔ Transforms resources
    representations in PHP objects

    View Slide

  22. Define The Resources
    Define your resources

    View Slide

  23. New: Import Your Data Model
    ✔ Create or use an existing
    RDF vocabulary…
    ✔ … or an OpenAPI Definition
    ✔ Run Schema Generator 5
    to generate the PHP classes
    $ bin/schema generate \
    src/ model-definition.yaml
    Design your API with Stoplight

    View Slide

  24. New: Improved Metadata
    ✔ PHP 8.1’s nested attributes
    ✔ Based on URI templates
    - Full control on the URL
    - Read+Write subresources
    - “Subresources” aren’t special anymore
    ✔ RDF & OpenAPI annotations (eg. types)

    View Slide

  25. Improved Metadata

    View Slide

  26. View Slide

  27. Resource-Oriented
    Framework
    PLUG YOUR BUSINESS LOGIC

    View Slide

  28. Hook Your Domain

    View Slide

  29. State Provider

    View Slide

  30. State Processor

    View Slide

  31. View Slide

  32. Still Natively Supported
    ✔ Doctrine ORM
    - Postgres, SQLite, MySQL, MariaDB,
    Oracle, DB2, SQL Server
    ✔ Doctrine MongoDB ODM
    ✔ ElasticSearch (read-only)
    Use them (only) when needed!

    View Slide

  33. 02 - Improved
    Developer
    eXperience

    View Slide

  34. New: Better Onboarding
    $ docker compose up
    ✔ Buildkit, Docker Compose v2
    ✔ Faster and less frequent builds
    ✔ Faster on Mac and Windows
    ✔ Cleaner Caddy and PHP config
    ✔ Still prod-ready (Kubernetes…)

    View Slide

  35. New: Native Xdebug Support
    $ XDEBUG_MODE=debug docker compose up

    View Slide

  36. New: Better Next Integration
    ✔ Brand new Dockerfile
    ✔ pnpm instead of yarn
    ✔ Output File Tracing for prod
    ✔ Faster builds
    ✔ Slimmer image

    View Slide

  37. 03 - Standalone
    Client Tools

    View Slide

  38. API Platform Admin
    ✔ OpenAPI support, works with any API
    ✔ Real-time updates with Mercure
    (if enabled on your API)
    ✔ Improved performance
    ✔ Better Schema.org compatibility
    ✔ Uses React Admin 4.3

    View Slide

  39. API Platform Create Client
    ✔ OpenAPI support, works with any API
    ✔ Improved skeletons
    - TypeScript
    - Mercure
    - Modern libs
    $ pnpm create \
    @api-platform/client

    View Slide

  40. 04 - New Roadmap

    View Slide

  41. New Roadmap
    ✔ Major version every 2 years
    - Deprecated code removal
    - Drop support for non-current Symfony
    ✔ Minor version every 6 months
    ✔ Upgrade path:
    last minor = new major + backward compatibility

    View Slide

  42. New Roadmap
    ✔ September 2022: API Platform 3 and 2.6
    ✔ November 2023: Symfony 7.0
    ○ API Platform 3.2: compat wit Symfony 6 and 7
    ✔ September 2024: API Platform 4.0 & 3.4
    ○ API Platform 4.0: Symfony 7 only
    ✔ 🔁

    View Slide

  43. View Slide

  44. Thank you!
    ENJOY THE CONFERENCE!
    @dunglas
    dunglas;fr
    Questions during the Q&A session!

    View Slide