Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

API Platform : The API-first Framework

Slide 3

Slide 3 text

@dunglas API Platform: key points A rock-solid API-first project in minutes State-of-the-art API technologies:
 hypermedia, Mercure, Vulcain, GraphQL … Batteries included:
 create (server), consume (clients) and deploy Customizable, extensible, modular

Slide 4

Slide 4 text

Main components

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Getting Started

Slide 7

Slide 7 text

@dunglas Docker All you need is (and it’s optional)

Slide 8

Slide 8 text

@dunglas Install Download the latest release on api-platform.com https://localhost $ docker-compose up

Slide 9

Slide 9 text

The basics

Slide 10

Slide 10 text

@dunglas Design AND Code First Design the public data model exposed by your AP I Describe it as a set of Data Transfer Objects (DTO ) Add types Embed human-readable docs

Slide 11

Slide 11 text

@dunglas Design AND Code First namespace App\Entity; use ApiPlatform\Core\Annotation\ApiResource; /** * A book * * @ApiResource */ class Book { /** Identifier of the book */ public string $id; /** Title of the book */ public string $title; public function __construct(string $id, string $title) { $this->id = $id; $this->title = $title; } }

Slide 12

Slide 12 text

Standard REST routes ar e automatically registered

Slide 13

Slide 13 text

Machine-readable API docs are dynamically generated from PHP class metadata : ❏ Hydra / RD F ❏ OpenAPI v2 (aka Swagger) and v 3 ❏ GraphQL schem a ❏ JSON Schema

Slide 14

Slide 14 text

@dunglas Plug your domain: read class BookDataProvider implements /* Item|Collection|… */DataProviderInterface { public function getCollection(string $resourceClass /*…*/): iterable { // Return the collection of Book objects (can be a paged collection) // matching the passed criteria } public function getItem(string $resourceClass, $id /*…*/): Book { // Return the Book object having this ID } public function supports(string $resourceClass /*…*/): bool { // Register as many data providers as needed return $resourceClass === Book::class; } }

Slide 15

Slide 15 text

@dunglas Plug your domain: write class BookDataPersister implements /*…*/DataPersisterInterface { public function persist($data /*…*/) { // Extract the data from the DTO and use it } public function remove($data /*…*/) { // Remove this resource } public function supports($data /*…*/): bool { // Plug as many data persisters as needed return $data instanceof Book; } }

Slide 16

Slide 16 text

@dunglas Enjoy the Built-in Features! Aut h Validatio n Paginatio n Filterin g Sortin g Real-time Push: Mercur e Rels preloading: Vulcai n Docs: Swagger UI, Redoc, GraphiQL… Automated test s Hypermedi a HTTP/ 2 RDF / JSON-LD / Hydr a GraphQ L JSON:AP I HA L JSON Schem a …

Slide 17

Slide 17 text

Symfon y Integrations

Slide 18

Slide 18 text

@dunglas Available Integrations Core: a standalone PHP lib built on top of Symfony Component s Symfony Bundle: Symfony Framework integratio n Doctrine Bridge: automatic persistence with Doctrine ORM (read/write ) MongoDB Bridge: automatic persistence with Doctrine MongoDB ODM (read/write ) Elasticsearch Bridge: ES integration (read-only)

Slide 19

Slide 19 text

@dunglas Automatic Persistenc e (maybe NOT what you need) /** * @ApiResource * @ORM\Entity */ class Book { /* … */ }

Slide 20

Slide 20 text

@dunglas No Code: MakerBundle

Slide 21

Slide 21 text

Conference-Driven Development

Slide 22

Slide 22 text

@dunglas API Platform 2.5: 1+ year old

Slide 23

Slide 23 text

API Platform 2.6 alph a is out!

Slide 24

Slide 24 text

Core Lib
 New Features

Slide 25

Slide 25 text

@dunglas PHP 8 Attributes use ApiPlatform\Core\Annotation\ApiResource; #[ApiResource] class Book { public function __construct( public string $id, public string $title, ) {} }

Slide 26

Slide 26 text

@dunglas Global Defaults Contributed by Benoît Polaszek ❤ # config/packages/api_platform.yaml api_platform: defaults: itemOperations: ["get"] collectionOperations: ["get"] mercure: true # This config is applied to all 
 operations of all resources!

Slide 27

Slide 27 text

@dunglas Access Control For Properties use ApiPlatform\Core\Annotation\ApiProperty; class Book { #[\ApiProperty(security: "is_granted('ROLE_ADMIN')"] public $adminOnlyProperty; // Only admins will see the adminOnlyProperty prop } Contributed by Frédéric Barthelet & Grégoire Hébert ❤

Slide 28

Slide 28 text

@dunglas More New Features Full PHP 8 compatibility ❤ Pierre du Plessis, Antoine Bluchet & me GraphQL subscriptions (using Mercure) ❤ Alan Poulain Mercure support for MongoDB ❤ Alan Poulain Support for @Ignore & @SerializedName Serializer annotations ❤ Alexander Janssen, Marcel Malberg & MartkCz Brand new OpenAPI docs builder ❤ Antoine Bluchet Better support for composed identifiers ❤ Antoine Bluchet Improved Vulcain support ❤ Pierre Thibaudeau and many others

Slide 29

Slide 29 text

Client Generator

Slide 30

Slide 30 text

@dunglas API Platform Client Generator Scaffolds client apps by parsing API doc s Supports Hydra (preferred) and OpenAPI (experimental ) Pluggable skeletons: bring your own ! Works with any APIs (even if not written in PHP)

Slide 31

Slide 31 text

@dunglas Pre-existing Generators TypeScript model definition s React + Redux (no SSR ) Vue.js (no SSR ) React Nativ e Quasa r Vuetify

Slide 32

Slide 32 text

@dunglas New Generator: Contributed by Grégory Copin ❤ Replace the old React/Redux
 generator in the distribution ! No config needed, TypeScrip t Server-Side Renderin g Smart bundling, route prefetching…

Slide 33

Slide 33 text

@dunglas New Generator: $ docker-compose exec client \ 
 generate-api-platform-client

Slide 34

Slide 34 text

@dunglas New Generator: Contributed by Alain Hippolyte ❤ Easy to learn (good old HTML/JS/CSS ) Server-Side Renderin g Performant $ docker-compose exec client \ 
 generate-api-platform-client \ —-generator nuxt

Slide 35

Slide 35 text

API Platform UX

Slide 36

Slide 36 text

It’s the magic of REST’s layer system,
 but this can be hard to understand, and hard to manage in prod. + Varnish Cache in pro d

Slide 37

Slide 37 text

Caddy: Fewer Moving Parts

Slide 38

Slide 38 text

@dunglas Caddy Web Server Free and Open Source web serve r Super fast, written in G o Extensibl e Native PHP FPM support Automatic HTTPS, even for localhos t HTTP/3 ! Cloud native (API, hot config reloading… ) Can be used as a Kubernetes Ingress

Slide 39

Slide 39 text

@dunglas One Daemon To Rule Them All Caddy had almost everything needed by most Symfony / API Platform projects except : a Mercure module (async APIs, push ) a Vulcain module (RESTful relations preloading ) an HTTP cache module

Slide 40

Slide 40 text

A Mercure Module for Caddy

Slide 41

Slide 41 text

A Vulcain Module for Caddy

Slide 42

Slide 42 text

An HTTP Cache Module for Caddy

Slide 43

Slide 43 text

@dunglas Docker Services in APIP 2.6 PHP FP M Caddy server (with all modules ) Postgres (optional ) Node / NextJS (optional ) client and admin containers have been merged in a single React app

Slide 44

Slide 44 text

What If I Only Use The PHP Lib?

Slide 45

Slide 45 text

@dunglas Introducing Symfony Docker Same Caddy-based setu p But only PHP and Symfony ! No Postgres, no Node

Slide 46

Slide 46 text

@dunglas New: Symfony Flex’s Docker Configurator $ docker-compose exec php \ composer req orm Doctrine, a Postgres service and the pdo_pgsql driver are installed! $ docker-compose exec php \ composer req api API Platform (PHP only) is installed!

Slide 47

Slide 47 text

@dunglas I Don’t Want Docker At All! A version of Caddy, including the same modules as in Symfony's Docker is available as a standalone binary . You can also build your own binary and include only the modules you want: $ xcaddy build \ —-with github.com/dunglas/mercure/caddy \ —-with github.com/dunglas/vulcain/caddy

Slide 48

Slide 48 text

A New Component : ActivityPub

Slide 49

Slide 49 text

We Must Save The Web

Slide 50

Slide 50 text

@dunglas The ActivityPub Protocol A decentralized social networking protoco l W3C Recommendatio n Servers are interoperable and can be federated: the fediverse Implemented by Mastodon (Twitter-like), PeerTube (YouTube-like), PixelFed (Instagram- like), Mobilizon (Meetup-like)…

Slide 51

Slide 51 text

Build Your Decentralized App:

Slide 52

Slide 52 text

Community

Slide 53

Slide 53 text

@dunglas Community API Platform exists thanks to its communit y 590 contributors ❤ code, docs, community support,
 propaganda (aka evangelization) … 6,3K GitHub stars, 5M+ download s ~30 repositories written in PHP, JS, Go, Shell … An awesome sponsor:

Slide 54

Slide 54 text

A Brand New Community Section

Slide 55

Slide 55 text

A Page For Each Contributor!

Slide 56

Slide 56 text

And Even T-Shirts!

Slide 57

Slide 57 text

API Platform Version 3

Slide 58

Slide 58 text

@dunglas Next Release: API Platform 3 Upgrade path: API Platform 3 = API Platform 2.7 minus the backward compatibility layer
 (same as Symfony ) PHP 8 only ! Revamped subresources, with write support Revamped UX

Slide 59

Slide 59 text

If you like my work,
 consider sponsoring me on GitHub:

Slide 60

Slide 60 text

test API Platform 2.6 alpha Thank you! @dunglas - api-platform.com