Top Banner
API PLATFORM Full Stack Framework Resurrection
87

API Platform: Full Stack Framework Resurrection

Jan 21, 2018

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: API Platform: Full Stack Framework Resurrection

API PLATFORMFull Stack Framework Resurrection

Page 2: API Platform: Full Stack Framework Resurrection

Kévin DunglasFounder of Les-Tilleuls.coop

Symfony Core Team

API Platform creator

@dunglas

Page 3: API Platform: Full Stack Framework Resurrection

Les-Tilleuls.coopSelf-managed company since 2011

100% owned by employees

25 people, 97% growth in 2016

Hiring in London, Paris and Lille: [email protected]

Page 4: API Platform: Full Stack Framework Resurrection

The Web of 2017

Page 5: API Platform: Full Stack Framework Resurrection
Page 6: API Platform: Full Stack Framework Resurrection

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…

Page 7: API Platform: Full Stack Framework Resurrection

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…

Page 8: API Platform: Full Stack Framework Resurrection

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)

Page 9: API Platform: Full Stack Framework Resurrection

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

Page 10: API Platform: Full Stack Framework Resurrection

A Frameworkfor the Modern Web

Page 11: API Platform: Full Stack Framework Resurrection

Goals

Modern API formats

A rock-solid API-first project in minutes

Batteries included:create, consume and deploy the API

Customizable, extensible, modular:config, events, decoration…

Page 12: API Platform: Full Stack Framework Resurrection

They already Use API Platform

Page 13: API Platform: Full Stack Framework Resurrection

Getting Started

Page 14: API Platform: Full Stack Framework Resurrection

Get DockerIf you don’t have it yet…

Page 15: API Platform: Full Stack Framework Resurrection

Install

Grab a release on GitHub

Browse https://localhost

$ docker-compose up

Page 16: API Platform: Full Stack Framework Resurrection
Page 17: API Platform: Full Stack Framework Resurrection

Just 1 class

Page 18: API Platform: Full Stack Framework Resurrection

Included (v2.1 - stable)

PHP FPM and Nginx containers, sensitive defaults for Symfony

Varnish container (more about this later)

Cross-platform Docker setup

MySQL container

Symfony Edition fine tuned for APIs

Page 19: API Platform: Full Stack Framework Resurrection

Upcoming Changes

HTTP/2 and HTTPS dev proxy

Containers for JS dev 🤔 🤗

Symfony Standard Edition Symfony Flex

Simplified directory structure

MySQL PostgreSQL

api-platform/api-platform#422

Page 20: API Platform: Full Stack Framework Resurrection

Too Much?

Page 21: API Platform: Full Stack Framework Resurrection

Go Micro with Flex

Browse http://localhost:8000

$ composer create-p symfony/skeleton api $ cd api $ composer req api

$ make serve

Page 22: API Platform: Full Stack Framework Resurrection

Your Turn!

Page 23: API Platform: Full Stack Framework Resurrection

Create yourClass

PHPDoc extraction (optional)

The hook:@ApiResourceXML and YAML also supported

Doctrine integration (optional)

$ docker-compose exec php bin/console \ doctrine:schema:update --force

Plain Old PHP Object

Page 24: API Platform: Full Stack Framework Resurrection

Your 1st API is ready!

Page 25: API Platform: Full Stack Framework Resurrection
Page 26: API Platform: Full Stack Framework Resurrection

Out of the Box Features

JSON-LD + Hydra formatsBut also… JSONAPI, HAL, XML, YAML, CSV and raw JSON…

OpenAPI (aka Swagger) doc

Nice UI (Swagger UI)

POST, GET (item and lists), PUT, DELETE

Pagination for lists (30 items per page), fully configurable

Page 27: API Platform: Full Stack Framework Resurrection

Data Validation

Page 28: API Platform: Full Stack Framework Resurrection

Symfony

Validation groups

Error levels

Symfony Validator integration

Page 29: API Platform: Full Stack Framework Resurrection
Page 30: API Platform: Full Stack Framework Resurrection

Relations

Page 31: API Platform: Full Stack Framework Resurrection

Class with a Relation

Page 32: API Platform: Full Stack Framework Resurrection
Page 33: API Platform: Full Stack Framework Resurrection

Embedding Relations

Page 34: API Platform: Full Stack Framework Resurrection

Embedded Relations

Page 35: API Platform: Full Stack Framework Resurrection

HTTP Cache (invalidation)

Page 36: API Platform: Full Stack Framework Resurrection

HTTP cache (invalidation)GET responses generated only 1 time, then served by Varnish(also work with CloudFlare and any cache proxy supporting tags)

Responses tagged with IRIs (URLs) of resources they contain(including relations, embedded resources…)

When a write operation occurs cached responses containing outdated data are purged

Builtin, single config flag, trusted proxies config provided

Browse https://localhost:444

Page 37: API Platform: Full Stack Framework Resurrection

Other Features

Page 38: API Platform: Full Stack Framework Resurrection
Page 39: API Platform: Full Stack Framework Resurrection

How does it Work?

Page 40: API Platform: Full Stack Framework Resurrection

Core Library

Page 41: API Platform: Full Stack Framework Resurrection

Distribution

Compatible with all existing bundles

Shipped with Doctrine ORM(soft dependency)

Flex app

Automatic route registration

Page 42: API Platform: Full Stack Framework Resurrection

Metadata Subsystem

Properties’ types and relations extracted with Symfony PropertyInfo

Guesses API’s structure (resources and properties)from classes marked@ApiResource

Intermediate representation of the API structure

Used by Hypermedia normalizers (JSON-LD, Hydra, HAL…)registered in the Symfony Serializer

Page 43: API Platform: Full Stack Framework Resurrection

Event-Driven Architecture

Page 44: API Platform: Full Stack Framework Resurrection

JSON-LD and Hydra

Page 45: API Platform: Full Stack Framework Resurrection

Credit: Martin Fowlerhttp://martinfowler.com/articles/richardsonMaturityModel.html

Page 46: API Platform: Full Stack Framework Resurrection

JSON-LDStandardized 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

Page 47: API Platform: Full Stack Framework Resurrection
Page 48: API Platform: Full Stack Framework Resurrection
Page 49: API Platform: Full Stack Framework Resurrection
Page 50: API Platform: Full Stack Framework Resurrection
Page 51: API Platform: Full Stack Framework Resurrection
Page 52: API Platform: Full Stack Framework Resurrection
Page 53: API Platform: Full Stack Framework Resurrection

Hydra

auto-discoverable API:resources, properties, types, operations

Standardize common API structures:collections, paginations, filters, errors…

In-band API doc

Draft W3C

Page 54: API Platform: Full Stack Framework Resurrection
Page 55: API Platform: Full Stack Framework Resurrection
Page 56: API Platform: Full Stack Framework Resurrection
Page 57: API Platform: Full Stack Framework Resurrection

Client-sidetools

Page 58: API Platform: Full Stack Framework Resurrection

Create React App

Babel: JavaScript compiler (ES2015+, JSX, Flow…)

App skeleton generator

All tools and configs to get started:

Webpack: module bundler (compile and package JS, CSS…)

$ yarn global add create-react-app $ create-react-app my-app $ cd my-app

$ yarn start

ESLint: find and report bugs, bad patterns…

Integrated web server, live reload, dev and debug tools

Page 59: API Platform: Full Stack Framework Resurrection
Page 60: API Platform: Full Stack Framework Resurrection
Page 61: API Platform: Full Stack Framework Resurrection

Data Fixtures

Page 62: API Platform: Full Stack Framework Resurrection

More Properties

Page 63: API Platform: Full Stack Framework Resurrection

More Properties

Page 64: API Platform: Full Stack Framework Resurrection

Install$ docker-compose exec php \ composer req \ doctrine/data-fixtures:^1.2 \ nelmio/alice:^3.0 \ logger \ theofidry/alice-data-fixtures:^1.0@beta \ hautelook/alice-bundle:^2.0@beta

Page 65: API Platform: Full Stack Framework Resurrection

Loading Fixtures

$ docker-compose exec php bin/console hautelook:fixtures:load

Page 66: API Platform: Full Stack Framework Resurrection

Admin

Page 67: API Platform: Full Stack Framework Resurrection

API Platform AdminSonata EasyAdmin-like but as a React PWA

Built on top of Admin On Rest (by Marmelab)

Material Design

Automatically generates the admin by parsing the Hydra API doc

Browse https://localhost:8001

Page 68: API Platform: Full Stack Framework Resurrection
Page 69: API Platform: Full Stack Framework Resurrection

Alternatively…

$ yarn add @api-platform/admin

From any React installation:

Page 70: API Platform: Full Stack Framework Resurrection

Minimal Implementation

Page 71: API Platform: Full Stack Framework Resurrection

Customizing the Admin

Page 72: API Platform: Full Stack Framework Resurrection
Page 73: API Platform: Full Stack Framework Resurrection

Clients Generator

Page 74: API Platform: Full Stack Framework Resurrection

React PWA Generator (default)SensioGeneratorBundle-like, 100% client-side

Rock solid stack

$ yarn global add @api-platform/client-generator

Twitter Bootstrap support + accessibility (ARIA roles)

Use ES2015’s fetch()

Parse Hydra API doc to generate files

Page 75: API Platform: Full Stack Framework Resurrection
Page 76: API Platform: Full Stack Framework Resurrection
Page 77: API Platform: Full Stack Framework Resurrection
Page 78: API Platform: Full Stack Framework Resurrection

The StackReact, 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

Page 79: API Platform: Full Stack Framework Resurrection

Other SkeletonsReact Native: master branch (@mysiar)

TypeScript definitions: master branch (@soyuka)

Your preferred technology: Pull Requests very appreciated!

Angular: community (momenttech/lysis)

Vue.js: api-platform/client-generator#35 (@alOneh)

Page 80: API Platform: Full Stack Framework Resurrection

React Native

$ generate-api-platform-client \ http://localhost src/ \ —g react-native

Page 81: API Platform: Full Stack Framework Resurrection

Deploy in Clouds

Page 82: API Platform: Full Stack Framework Resurrection

Kubernetes & HelmK8S: « Production-Grade Container Orchestration », by Google

Powers Google Container Engine and Azure Container ServiceHelm: official K8S package manager (like APT or Homebrew), by MicrosoftFree software

Page 83: API Platform: Full Stack Framework Resurrection

Deploy in the CloudA 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 scale!

Page 84: API Platform: Full Stack Framework Resurrection

One More Thing…

Page 85: API Platform: Full Stack Framework Resurrection

GraphQL Support

$ composer req webonyx/graphql-php

api-platform/core#1358 (@alanpoulain)

Page 86: API Platform: Full Stack Framework Resurrection
Page 87: API Platform: Full Stack Framework Resurrection

Thanks!Any questions?

api-platform/api-platform @ApiPlatform

https://api-platform.com