Framework for API-driven Projects
@dunglas - Les-Tilleuls.coop
Kévin Dunglas
Founder of Les-Tilleuls.coop
Symfony Core Team
API Platform creator
@dunglas
@dunglas - Les-Tilleuls.coop
Les-Tilleuls.coop
Self-managed company since 2011
100% owned by employees
25 people, 97% growth in 2016
Hiring in London, Paris and Lille: jobs@les-tilleuls.coop
or
The Web in 2018
@dunglas - Les-Tilleuls.coop
APIs: the Heart of the New Web
@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…
@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…
@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)
@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
A Framework
for the Modern Web
@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…
Getting
Started
@dunglas - Les-Tilleuls.coop
Docker
All you need is
(but it’s optional)
@dunglas - Les-Tilleuls.coop
Install
Download the latest release on api-platform.com or GitHub
https://localhost
$ docker-compose up
@dunglas - Les-Tilleuls.coop
What’s Inside?
Postgres
Container 3: back office (dev)
Container 2: generated front office Progressive Web App (dev)
HTTP/2 and HTTPS proxy (dev)
Container 1: API Server (PHP + Symfony Flex)
Varnish cache (more later)
dev ➡ CI ➡ prod
Describe the
API Schema
@dunglas - Les-Tilleuls.coop
Map With the
Database
@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
@dunglas - Les-Tilleuls.coop
Your 1st API
is ready!
@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
Data
Validation
@dunglas - Les-Tilleuls.coop
Validation groups
Error levels
Symfony Validator integration
Custom validators
Filtering
@dunglas - Les-Tilleuls.coop
Creating custom filters is easy
8 built-in filters, with different strategies
Hypermedia
@dunglas - Les-Tilleuls.coop
Embedding
Relations
@dunglas - Les-Tilleuls.coop
@dunglas - Les-Tilleuls.coop
Embedded Relations
Cache Layer
(invalidation)
@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
Other
Features
@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
JSON-LD and Hydra
@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
@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
Client-side
tools
Admin
@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!
@dunglas - Les-Tilleuls.coop
Show Me the Code!
Clients
Generator
@dunglas - Les-Tilleuls.coop
React PWA Generator (default)
Scaffolds a client-side apps
Twitter Bootstrap support + accessibility (ARIA roles)
Uses ES2015’s fetch()
Parses Hydra API doc to generate files

(experimental Swagger support)
$ docker-compose exec client 

generate-api-platform-client
@dunglas - Les-Tilleuls.coop
The Stack
React, ES2015+, JSX
React Router: client-side routing library
Redux: extensible container to manage the states of the app
Redux Form: forms
Redux Thunk: async actions (AJAX requests)
Optional: Twitter Bootstrap
@dunglas - Les-Tilleuls.coop
Other Skeletons
React Native (@mysiar)
Your preferred technology: Pull Requests very appreciated!
TypeScript definitions (@soyuka)
Vue.js (@alOneh)
Angular (momenttech/lysis)
@dunglas - Les-Tilleuls.coop
React Native
$ generate-api-platform-client 
—g react-native
Deploy in
Clouds
@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
@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!
GraphQL?
@dunglas - Les-Tilleuls.coop
GraphQL Support
$ docker-compose exec php 

composer req webonyx/graphql-php
@dunglas - Les-Tilleuls.coop
They Already Use API Platform
@dunglas - Les-Tilleuls.coop
They Build API Platform
10 maintainers
MIT licensed (Free Open Source Software)
150+ contributors
2.9k GitHub Stars
3000+ commits
Thanks!
Any questions?
api-platform/api-platform @ApiPlatform
https://api-platform.com

API Platform: A Framework for API-driven Projects