During this talk, I'll present the main features of API Platform. We will install the framework, design an API data model as a set of tiny plain old PHP classes and learn how to get:
* A fully featured dev environment with Symfony Flex and React containers, HTTP/2 and HTTPS support and a cache proxy
* Pagination, data validation, access control, relation embedding, filters and error handling
* Support for modern REST API formats: JSON-LD/Hydra, OpenAPI/Swagger, JSONAPI, HAL, JSON…
* GraphQL support
* An API responding in a just few milliseconds thanks to the builtin invalidation based cache mechanism
* A dynamically created Material Design admin interface (a la Sonata / EasyAdmin – but 100% client-side) built with React
* Client apps skeletons: React/Redux, React Native, Vue.js, Angular…
Finally, we'll see ho to deploy the project in 1 command on Google Container Engine or any cloud with a Kubernetes.
9. @dunglas - Les-Tilleuls.coop
APIs: the Heart of the New Web
Central point to access data
Encapsulate the business logic
Same features available everywhere:
webapps, mobile apps, IoT, customers, providers…
10. @dunglas - Les-Tilleuls.coop
Progressive Web Apps
Downloaded only 1 time, works offline!
Sends async HTTP requests to the API
Huge ecosystem: React, Angular, Vue…
Holds the presentation logic
Static « website »: JS, HTML and CSS
Modernized stack:
ES2015, Babel, Webpack, Yarn, Flow, TypeScript, ReasonML…
11. @dunglas - Les-Tilleuls.coop
Native Mobile Apps
Sync data by sending HTTP requests to the API
JS stack:
React Native, NativeScript
Downloaded from stores (App Store, Google Play)
Look’n’Feel consistent with the platform (iOS or Android)
12. @dunglas - Les-Tilleuls.coop
Cloud Native Projects
Software built, tested and deployed continuously
Rich and open ecosystem:
Docker, Kubernetes, Mesos, Terraform…
Projects are hosted on public and private clouds
Containers and orchestration from dev stations to prod
14. @dunglas - Les-Tilleuls.coop
Goals
Modern API formats: JSON-LD, GraphQL…
A rock-solid API-first project in minutes
Batteries included:
create, consume and deploy the API
Customizable, extensible, modular:
config, events, decoration…
24. @dunglas - Les-Tilleuls.coop
Persistence
Public and internal models can be different
Work with any persistence layer: 2 interfaces to implement
Experimental ElasticSearch and MongoDB built-in support
RAD: built-in support for Doctrine ORM, 100% optional
Compatible with CQRS and Event Sourcing
28. @dunglas - Les-Tilleuls.coop
Out of the Box Features
JSON-LD + Hydra formats
But also… GraphQL, JSONAPI, HAL, YAML, CSV, XML, raw JSON…
OpenAPI (aka Swagger) support
API documentation (Swagger UI)
POST, GET (item and lists), PUT, DELETE
Pagination for lists (30 items per page), fully configurable
42. @dunglas - Les-Tilleuls.coop
HTTP cache (invalidation)
GET responses generated only 1 time, then served by Varnish
(can work with CloudFlare and Fastly too)
Responses are tagged with resources’s IDs they contain
(including relations, embedded resources…)
On write: cached responses containing stale data are purged
Builtin, single config flag
https://localhost:8444
44. @dunglas - Les-Tilleuls.coop
Other Features
Deprecation / API evolution
Extensible: compatible with all Symfony bundles
Every part can be replaced (dependency injection)
Authentification and authorization
46. @dunglas - Les-Tilleuls.coop
JSON-LD
Standardized hypermedia format: W3C recommandation (2014)
Easy to use: a standard JSON document with some specials
keys (starting with @) and mapped with a context
Backed by Google, BBC, Microsoft, US & UK govs...
Compliant with technologies of the semantic web: RDF,
SPARQL, triple store...
JSON for Linked Data
47.
48.
49.
50. @dunglas - Les-Tilleuls.coop
Hydra
Allow to create auto-discoverable APIs:
resources, properties, types, operations
Standard for common API structures:
collections, paginations, filters, errors…
In-band hypermedia API docs
W3C community group
54. @dunglas - Les-Tilleuls.coop
API Platform Admin
Material Design back office interface
Built on top of React Admin
Hypermedia: parses Hydra docs
100% dynamic: no code generation
https://localhost:444
100% client-side, 100% JS: work with any Hydra enabled API
100% customizable: bring your own React components!
65. @dunglas - Les-Tilleuls.coop
Kubernetes & Helm
k8s: « Production-Grade Container Orchestration »
Google GKE / Amazon EKS / Azure AKS
Helm: K8S package manager (like APT or Homebrew)
Open Source
66. @dunglas - Les-Tilleuls.coop
Deploy in the Cloud
A Helm chart is provided with API Platform
# …Build and push the Docker images…
# …Connect to your Kubernetes cluster…
$ helm install ./api/helm/api --name api
The project is deployed,
managed, and scales!