Creating a modern web
application using
Symfony API Platform
by Jesus Manuel Olivas / weKnow
@jmolivas
● $ whoami
Jesus Manuel Olivas
jmolivas@weknowinc.com
jmolivas
jmolivas
drupal.org/u/jmolivas
jmolivas.weknowinc.com
Mexicali

Mexico + California
Calexico

California + Mexico
$ ifconfig
WeAre
WeKnow
WeGive
2,572,697
Drupal … Drupal … Drupal
When all you have is a
hammer, everything looks
like a nail.
Creating a modern web application using  Symfony API Platform Atlanta
Traditional Monolithic CMS
Drupal Headless API + Front-end library
● Fetch
What if … you do not need
> Complex content model (paragraphs)
> Editorial workflow
> Revisions
> GUI to manage Queries (views)
> GUI to manage content model
> Widgets and formatters
Symfony API + Front-end library/framework
● API / GraphQL
Symfony
API Platform
GraphQL
 ReactJS
Symfony Flex
Symfony Flex … a Composer plugin for Symfony
> Symfony Flex is a Composer plugin that modifies the behavior of
the require, update, and remove composer commands.
> Symfony Flex automates the most common tasks of Symfony
applications, like installing and removing bundles and other
dependencies using recipes defined in a manifest.json file.
Directory structure
API Platform 
Framework
The API Platform Framework
REST and GraphQL
framework to build
modern API-driven
projects
https://api-platform.com/
Built on the Shoulders of Giants
> Extend the framework with thousands of existing Symfony
bundles and React components.
> The API component includes the Symfony 4 flex, the Doctrine ORM.
Client-side components and Admin based on React and a Docker
configuration ready to startup your project using one single command.
> Reuse all your Symfony, React and Docker skills and benefit of their high
quality docs; you are in known territory.
The API Platform Components
API Schema Admin CRUD
Try API-Platform
# Clone code repository

git clone https://github.com/api-platform/api-platform.git
Recommendations and adjustments
> Update route prefix at api/config/routes/api_platform.yaml
file.
api_platform:

…

prefix: /api
> Update admin/.env and client/.env files (change protocol and port).
REACT_APP_API_ENTRYPOINT=http://localhost:8080/api
Start containers … and grab water, coffee, or a beer.
# Start containers
docker-compose up
# Open browser
open http://localhost/
Add more formats
Update api/config/packages/api_platform.yaml adding:
formats:
jsonld: [‘application/ld+json'] # first one is the default format
json: ['application/json']
jsonhal: ['application/hal+json']
xml: ['application/xml', 'text/xml']
yaml: ['application/x-yaml']
csv: ['text/csv']
html: ['text/html']
Remove default & add new entities
> Remove default entity

api/src/Entity/Greeting.php
> Add new entities to api/src/Entity/ directory:

console make:entity
Creating a modern web application using  Symfony API Platform Atlanta
Creating a modern web application using  Symfony API Platform Atlanta
Creating a modern web application using  Symfony API Platform Atlanta
Creating a modern web application using  Symfony API Platform Atlanta
api/src/Entity/Post.php 1/3
<?php

namespace AppEntity;



use ApiPlatformCoreAnnotationApiResource;

use DoctrineORMMapping as ORM;

use SymfonyComponentValidatorConstraints as Assert;
/**

* @ApiResource

* @ORMTable(name="post")

* @ORMEntity

*/
class Post
{
…
}
api/src/Entity/Post.php 2/3
/**

* @ORMId

* @ORMGeneratedValue(strategy="AUTO")

* @ORMColumn(type="integer")

*/

private $id;
/**

* @ORMColumn

* @AssertNotBlank

*/

public $title = '';

/**

* @ORMColumn
* @AssertNotBlank
*/
public $body = '';
api/src/Entity/Post.php 3/3
/**
* @ORMManyToOne(targetEntity="PostType")
* @ORMJoinColumn(name="post_type_id", referencedColumnName="id", nullable=false)
*/
public $type;
public function getId(): int
{
return $this->id;
}
Tracking Database changes
# Add dependency
composer require migrations
# Execute command(s)
console make:migration
console doctrine:migrations:migrate
Add FOSUserBundle
# Add dependency
composer require friendsofsymfony/user-bundle
composer require symfony/swiftmailer-bundle
https://symfony.com/doc/current/bundles/FOSUserBundle/index.html
https://jolicode.com/blog/do-not-use-fosuserbundle
Loading Posts using the Browser
http://localhost:8080/api/posts
http://localhost:8080/api/posts.json
http://localhost:8080/api/posts.jsonld
http://localhost:8080/api/posts/1
http://localhost:8080/api/posts/1.json
Loading Posts using the CLI
curl -X GET "http://localhost:8080/api/posts" 
-H "accept: application/json"
curl -X GET "http://localhost:8080/api/posts/1" 
-H "accept: application/ld+json"
ADD Posts from CLI
curl -X POST "http://localhost:8080/api/posts" 
-H "accept: application/ld+json" 
-H "Content-Type: application/ld+json" 
-d '{ "title": "Post create from CLI", "body": "body-
less", "type": "/api/post_types/1"}'
UPDATE and REMOVE Posts from CLI
curl -X PUT "http://localhost:8080/api/posts/9" 
-H "accept: application/ld+json" 
-H "Content-Type: application/ld+json" 
-d '{ "title": "Updated from CLI"}'
curl -X DELETE "http://localhost:8080/api/posts/10" 
-H "accept: application/json"
Serialization
> API Platform allows to specify the which attributes of the resource are
exposed during the normalization (read) and denormalization (write)
process. It relies on the serialization (and deserialization) groups feature of
the Symfony Serializer component.
> In addition to groups, you can use any option supported by the Symfony
Serializer such as enable_max_depth to limit the serialization depth.
Serialization Relations (Post => PostType) 1/2
# api/src/Entity/Post.php & PostType.php
* @ApiResource(attributes={
* "normalization_context"={"groups"={"read"}},
* "denormalization_context"={"groups"={"write"}}
* })
Serialization Relations (Post => PostType) 2/2
# Add use keyword to class
use SymfonyComponentSerializerAnnotationGroups;
# Add use keyword to properties
* @Groups({"read"})
* @Groups({"read", "write"})
GraphQL
A query language for your API
GraphQL
GraphQL offers significantly more flexibility for integrators.
Allows you to define in detail the only the data you want.
GraphQL lets you replace multiple REST requests with a single
call to fetch the data you specify.
Add GraphQL
To enable GraphQL and GraphiQL interface in your API, simply require
the graphql-php package using Composer:
composer require webonyx/graphql-php
open http://localhost:8080/api/graphql
Disable GraphiQL
Update api/config/packages/api_platform.yaml adding:
api_platform:
# ...
graphql:
graphiql:
enabled: false
# ...
Load resource using GraphQL
{
post (id:"/api/posts/1") {
id,
title,
body
}
}
Load resource using GraphQL form the CLI
curl -X POST 
-H "Content-Type: application/json" 
-d '{ "query": "{ post(id:"/api/posts/1") { id,
title, body }}" }' 
http://localhost:8080/api/graphql
Load resource relations using GraphQL
{
post (id:"/api/posts/1") {
title,
body,
type {
id,
name
}
}
}
Load resource relations using GraphQL form the CLI
curl -X POST 
-H "Content-Type: application/json" 
-d '{ "query": "{ post(id:"/api/posts/1") { id, title,
body, type { id, name } }}" }' 
http://localhost:8080/api/graphql
JWT
Authentication
Creating a modern web application using  Symfony API Platform Atlanta
JWT Dependencies
# JWT

composer require lexik/jwt-authentication-bundle
JWT Refresh

gesdinet/jwt-refresh-token-bundle
JWT Events (create)
# config/services.yaml

AppEventListenerJWTCreatedListener:

tags:

- {

name: kernel.event_listener, 

event: lexik_jwt_authentication.on_jwt_created,

method: onJWTCreated

}


# src/EventListener/JWTCreatedListener.php

public function onJWTCreated(JWTCreatedEvent $event)

{

$data = $event->getData();

$user = $event->getUser();

$data['organization'] = $user->getOrganization()->getId();

$event->setData($data);

}
JWT Events (success)
# config/services.yaml

AppEventListenerAuthenticationSuccessListener:

tags:

- {

name: kernel.event_listener, 

event: lexik_jwt_authentication.on_authentication_success,

method: onAuthenticationSuccessResponse

}

# src/EventListener/AuthenticationSuccessListener.php

public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event) 

{

$data = $event->getData();

$user = $event->getUser();

$data[‘roles'] = $user->getOrganization()->getRoles();

$event->setData($data);

}
React+Redux+Saga+
AntDesign
dvajs/dva - React and redux based framework. 
https://github.com/dvajs/dva
React / Redux / Saga / AntDesign
> Use webpack instead of roadhog.
> Use apollo-fetch for GraphQL calls.
> Use jwt-decode to interact with JWT.
> Use LocalStorage for simple key/values storage.
> Use IndexedDB for encrypted and/or more complex data structures.
> Use Socket-IO + Redis to sync & communicate between API & ReactJS.
Tips
Headless approach
Symfony API + Gatsby
● API / GraphQL
Blazing fast site generator for React
Creating a modern web application using  Symfony API Platform Atlanta
● Build● API / GraphQL
Must have plugins
• gatsby-source-graphql
• gatsby-transformer-remark
• gatsby-remark-images
• gatsby-remark-external-links
• gatsby-plugin-sharp
• gatsby-transformer-sharp
• gatsby-plugin-react-helmet
Choose the right tool for
the job
Thank you … Questions?
Feel free to ping me during the event,
at the parties, after-parties, and twitter @jmolivas

More Related Content

PDF
Creating a modern web application using Symfony API Platform, ReactJS and Red...
PDF
Ruby on Rails
PDF
Symfony3 w duecie z Vue.js
PPTX
API Development with Laravel
PPTX
REST APIs in Laravel 101
PDF
Diseño y Desarrollo de APIs
PPTX
Build restful ap is with python and flask
ODP
Presentation laravel 5 4
Creating a modern web application using Symfony API Platform, ReactJS and Red...
Ruby on Rails
Symfony3 w duecie z Vue.js
API Development with Laravel
REST APIs in Laravel 101
Diseño y Desarrollo de APIs
Build restful ap is with python and flask
Presentation laravel 5 4

What's hot (20)

PDF
RESTful API development in Laravel 4 - Christopher Pecoraro
PDF
Laravel 101
PPTX
Workshop Laravel 5.2
PDF
API Platform and Symfony: a Framework for API-driven Projects
PDF
Bootstrat REST APIs with Laravel 5
PDF
RESTful API Design & Implementation with CodeIgniter PHP Framework
PPT
Building a p2 update site using Buckminster
PPTX
Laravel 5
PDF
170517 damien gérard framework facebook
PDF
Hello World on Slim Framework 3.x
ODP
Javascript laravel's friend
PPT
Red5 - PHUG Workshops
PPTX
Laravel Beginners Tutorial 2
PPTX
Laravel - Website Development in Php Framework.
PPTX
Power Shell and Sharepoint 2013
PPT
Building Single Page Application (SPA) with Symfony2 and AngularJS
PDF
The new features of PHP 7
PDF
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
PDF
Rails 4.0
PPTX
Webinar - Office 365 & PowerShell : A Match Made in Heaven
RESTful API development in Laravel 4 - Christopher Pecoraro
Laravel 101
Workshop Laravel 5.2
API Platform and Symfony: a Framework for API-driven Projects
Bootstrat REST APIs with Laravel 5
RESTful API Design & Implementation with CodeIgniter PHP Framework
Building a p2 update site using Buckminster
Laravel 5
170517 damien gérard framework facebook
Hello World on Slim Framework 3.x
Javascript laravel's friend
Red5 - PHUG Workshops
Laravel Beginners Tutorial 2
Laravel - Website Development in Php Framework.
Power Shell and Sharepoint 2013
Building Single Page Application (SPA) with Symfony2 and AngularJS
The new features of PHP 7
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Rails 4.0
Webinar - Office 365 & PowerShell : A Match Made in Heaven
Ad

Similar to Creating a modern web application using Symfony API Platform Atlanta (20)

PDF
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)
PDF
Building APIs in an easy way using API Platform
PPTX
Creating hypermedia APIs in a few minutes using the API Platform framework
PDF
A high profile project with Symfony and API Platform: beIN SPORTS
PDF
Using API platform to build ticketing system (translations, time zones, ...) ...
PDF
API Platform: Full Stack Framework Resurrection
PDF
Using API Platform to build ticketing system #symfonycon
PDF
REST easy with API Platform
PDF
High quality ap is with api platform
PDF
Build powerfull and smart web applications with Symfony2
PPTX
API Platform: The Pragmatic API framework
KEY
The use of Symfony2 @ Overblog
PDF
Symfony components in the wild, PHPNW12
PDF
Resting with OroCRM Webinar
PDF
The Naked Bundle - Symfony Barcelona
PDF
Алексей Веркеенко "Symfony2 & REST API"
PDF
Building APIs in an easy way using API Platform
PDF
Symfony2 San Francisco Meetup 2009
PDF
Drupal symfony
PPTX
A soa approximation on symfony
API Platform 2.1: when Symfony meets ReactJS (Symfony Live 2017)
Building APIs in an easy way using API Platform
Creating hypermedia APIs in a few minutes using the API Platform framework
A high profile project with Symfony and API Platform: beIN SPORTS
Using API platform to build ticketing system (translations, time zones, ...) ...
API Platform: Full Stack Framework Resurrection
Using API Platform to build ticketing system #symfonycon
REST easy with API Platform
High quality ap is with api platform
Build powerfull and smart web applications with Symfony2
API Platform: The Pragmatic API framework
The use of Symfony2 @ Overblog
Symfony components in the wild, PHPNW12
Resting with OroCRM Webinar
The Naked Bundle - Symfony Barcelona
Алексей Веркеенко "Symfony2 & REST API"
Building APIs in an easy way using API Platform
Symfony2 San Francisco Meetup 2009
Drupal symfony
A soa approximation on symfony
Ad

More from Jesus Manuel Olivas (20)

PDF
Remix & GraphQL: A match made in heaven with type-safety DX
PDF
Drupal 10 Party GraphQL
PDF
How to use Drupal to create editorial experiences your content creators will...
PDF
Beyond Static: Building a Dynamic Application with Gatsby
PDF
Drupal, GraphQL, Views, View Modes and Gatsby for a US Gov site CMS Philly
PDF
Embracing the modern web using a Headless CMS with GatsbyJS CMS Philly
PDF
Embracing the modern web using a Headless CMS with GatsbyJS Stanford
PDF
Building a modern application using Symfony API Platform and GatsbyJS PHP QRO
PDF
Building a dynamic application with GatsbyJS-Tec-Mexicali
PDF
Building a modern web application in the cloud partnercon
PDF
Embracing the modern web using Drupal as a Headless CMS with Gatsby BADCamp
PDF
Blazing fast sites using Blaze, Hybrid CMS NYC
PDF
Embracing the modern web using Drupal as Headless CMS with GatsbyJS NYC
PDF
Writing a slack chatbot seattle
PDF
Building a Modern Web Application in the Cloud TecNerd
PDF
How to keep Drupal relevant in the Git-based and API-driven CMS era Florida
PDF
How to keep Drupal relevant in the Git-based and API-driven CMS era DrupalCampNJ
PDF
Tools and Projects Dec 2018 Edition
PDF
How to keep Drupal relevant in the Git-based and API-driven CMS era - BADCamp
PDF
Battle of the CMS DrupalCampLA
Remix & GraphQL: A match made in heaven with type-safety DX
Drupal 10 Party GraphQL
How to use Drupal to create editorial experiences your content creators will...
Beyond Static: Building a Dynamic Application with Gatsby
Drupal, GraphQL, Views, View Modes and Gatsby for a US Gov site CMS Philly
Embracing the modern web using a Headless CMS with GatsbyJS CMS Philly
Embracing the modern web using a Headless CMS with GatsbyJS Stanford
Building a modern application using Symfony API Platform and GatsbyJS PHP QRO
Building a dynamic application with GatsbyJS-Tec-Mexicali
Building a modern web application in the cloud partnercon
Embracing the modern web using Drupal as a Headless CMS with Gatsby BADCamp
Blazing fast sites using Blaze, Hybrid CMS NYC
Embracing the modern web using Drupal as Headless CMS with GatsbyJS NYC
Writing a slack chatbot seattle
Building a Modern Web Application in the Cloud TecNerd
How to keep Drupal relevant in the Git-based and API-driven CMS era Florida
How to keep Drupal relevant in the Git-based and API-driven CMS era DrupalCampNJ
Tools and Projects Dec 2018 Edition
How to keep Drupal relevant in the Git-based and API-driven CMS era - BADCamp
Battle of the CMS DrupalCampLA

Recently uploaded (20)

PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Enhancing plagiarism detection using data pre-processing and machine learning...
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PPTX
The various Industrial Revolutions .pptx
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PDF
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
CloudStack 4.21: First Look Webinar slides
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
STKI Israel Market Study 2025 version august
DOCX
search engine optimization ppt fir known well about this
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
UiPath Agentic Automation session 1: RPA to Agents
PPTX
Build Your First AI Agent with UiPath.pptx
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
Developing a website for English-speaking practice to English as a foreign la...
Enhancing plagiarism detection using data pre-processing and machine learning...
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
The various Industrial Revolutions .pptx
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Zenith AI: Advanced Artificial Intelligence
1 - Historical Antecedents, Social Consideration.pdf
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
Flame analysis and combustion estimation using large language and vision assi...
CloudStack 4.21: First Look Webinar slides
A review of recent deep learning applications in wood surface defect identifi...
NewMind AI Weekly Chronicles – August ’25 Week III
STKI Israel Market Study 2025 version august
search engine optimization ppt fir known well about this
A contest of sentiment analysis: k-nearest neighbor versus neural network
UiPath Agentic Automation session 1: RPA to Agents
Build Your First AI Agent with UiPath.pptx

Creating a modern web application using Symfony API Platform Atlanta

  • 1. Creating a modern web application using Symfony API Platform by Jesus Manuel Olivas / weKnow @jmolivas
  • 2. ● $ whoami Jesus Manuel Olivas [email protected] jmolivas jmolivas drupal.org/u/jmolivas jmolivas.weknowinc.com
  • 7. Drupal … Drupal … Drupal
  • 8. When all you have is a hammer, everything looks like a nail.
  • 11. Drupal Headless API + Front-end library ● Fetch
  • 12. What if … you do not need > Complex content model (paragraphs) > Editorial workflow > Revisions > GUI to manage Queries (views) > GUI to manage content model > Widgets and formatters
  • 13. Symfony API + Front-end library/framework ● API / GraphQL
  • 16. Symfony Flex … a Composer plugin for Symfony > Symfony Flex is a Composer plugin that modifies the behavior of the require, update, and remove composer commands. > Symfony Flex automates the most common tasks of Symfony applications, like installing and removing bundles and other dependencies using recipes defined in a manifest.json file.
  • 19. The API Platform Framework REST and GraphQL framework to build modern API-driven projects https://api-platform.com/
  • 20. Built on the Shoulders of Giants > Extend the framework with thousands of existing Symfony bundles and React components. > The API component includes the Symfony 4 flex, the Doctrine ORM. Client-side components and Admin based on React and a Docker configuration ready to startup your project using one single command. > Reuse all your Symfony, React and Docker skills and benefit of their high quality docs; you are in known territory.
  • 21. The API Platform Components API Schema Admin CRUD
  • 22. Try API-Platform # Clone code repository
 git clone https://github.com/api-platform/api-platform.git
  • 23. Recommendations and adjustments > Update route prefix at api/config/routes/api_platform.yaml file. api_platform:
 …
 prefix: /api > Update admin/.env and client/.env files (change protocol and port). REACT_APP_API_ENTRYPOINT=http://localhost:8080/api
  • 24. Start containers … and grab water, coffee, or a beer. # Start containers docker-compose up # Open browser open http://localhost/
  • 25. Add more formats Update api/config/packages/api_platform.yaml adding: formats: jsonld: [‘application/ld+json'] # first one is the default format json: ['application/json'] jsonhal: ['application/hal+json'] xml: ['application/xml', 'text/xml'] yaml: ['application/x-yaml'] csv: ['text/csv'] html: ['text/html']
  • 26. Remove default & add new entities > Remove default entity
 api/src/Entity/Greeting.php > Add new entities to api/src/Entity/ directory:
 console make:entity
  • 31. api/src/Entity/Post.php 1/3 <?php
 namespace AppEntity;
 
 use ApiPlatformCoreAnnotationApiResource;
 use DoctrineORMMapping as ORM;
 use SymfonyComponentValidatorConstraints as Assert; /**
 * @ApiResource
 * @ORMTable(name="post")
 * @ORMEntity
 */ class Post { … }
  • 32. api/src/Entity/Post.php 2/3 /**
 * @ORMId
 * @ORMGeneratedValue(strategy="AUTO")
 * @ORMColumn(type="integer")
 */
 private $id; /**
 * @ORMColumn
 * @AssertNotBlank
 */
 public $title = '';
 /**
 * @ORMColumn * @AssertNotBlank */ public $body = '';
  • 33. api/src/Entity/Post.php 3/3 /** * @ORMManyToOne(targetEntity="PostType") * @ORMJoinColumn(name="post_type_id", referencedColumnName="id", nullable=false) */ public $type; public function getId(): int { return $this->id; }
  • 34. Tracking Database changes # Add dependency composer require migrations # Execute command(s) console make:migration console doctrine:migrations:migrate
  • 35. Add FOSUserBundle # Add dependency composer require friendsofsymfony/user-bundle composer require symfony/swiftmailer-bundle https://symfony.com/doc/current/bundles/FOSUserBundle/index.html https://jolicode.com/blog/do-not-use-fosuserbundle
  • 36. Loading Posts using the Browser http://localhost:8080/api/posts http://localhost:8080/api/posts.json http://localhost:8080/api/posts.jsonld http://localhost:8080/api/posts/1 http://localhost:8080/api/posts/1.json
  • 37. Loading Posts using the CLI curl -X GET "http://localhost:8080/api/posts" -H "accept: application/json" curl -X GET "http://localhost:8080/api/posts/1" -H "accept: application/ld+json"
  • 38. ADD Posts from CLI curl -X POST "http://localhost:8080/api/posts" -H "accept: application/ld+json" -H "Content-Type: application/ld+json" -d '{ "title": "Post create from CLI", "body": "body- less", "type": "/api/post_types/1"}'
  • 39. UPDATE and REMOVE Posts from CLI curl -X PUT "http://localhost:8080/api/posts/9" -H "accept: application/ld+json" -H "Content-Type: application/ld+json" -d '{ "title": "Updated from CLI"}' curl -X DELETE "http://localhost:8080/api/posts/10" -H "accept: application/json"
  • 40. Serialization > API Platform allows to specify the which attributes of the resource are exposed during the normalization (read) and denormalization (write) process. It relies on the serialization (and deserialization) groups feature of the Symfony Serializer component. > In addition to groups, you can use any option supported by the Symfony Serializer such as enable_max_depth to limit the serialization depth.
  • 41. Serialization Relations (Post => PostType) 1/2 # api/src/Entity/Post.php & PostType.php * @ApiResource(attributes={ * "normalization_context"={"groups"={"read"}}, * "denormalization_context"={"groups"={"write"}} * })
  • 42. Serialization Relations (Post => PostType) 2/2 # Add use keyword to class use SymfonyComponentSerializerAnnotationGroups; # Add use keyword to properties * @Groups({"read"}) * @Groups({"read", "write"})
  • 43. GraphQL A query language for your API
  • 44. GraphQL GraphQL offers significantly more flexibility for integrators. Allows you to define in detail the only the data you want. GraphQL lets you replace multiple REST requests with a single call to fetch the data you specify.
  • 45. Add GraphQL To enable GraphQL and GraphiQL interface in your API, simply require the graphql-php package using Composer: composer require webonyx/graphql-php open http://localhost:8080/api/graphql
  • 46. Disable GraphiQL Update api/config/packages/api_platform.yaml adding: api_platform: # ... graphql: graphiql: enabled: false # ...
  • 47. Load resource using GraphQL { post (id:"/api/posts/1") { id, title, body } }
  • 48. Load resource using GraphQL form the CLI curl -X POST -H "Content-Type: application/json" -d '{ "query": "{ post(id:"/api/posts/1") { id, title, body }}" }' http://localhost:8080/api/graphql
  • 49. Load resource relations using GraphQL { post (id:"/api/posts/1") { title, body, type { id, name } } }
  • 50. Load resource relations using GraphQL form the CLI curl -X POST -H "Content-Type: application/json" -d '{ "query": "{ post(id:"/api/posts/1") { id, title, body, type { id, name } }}" }' http://localhost:8080/api/graphql
  • 53. JWT Dependencies # JWT
 composer require lexik/jwt-authentication-bundle JWT Refresh
 gesdinet/jwt-refresh-token-bundle
  • 54. JWT Events (create) # config/services.yaml
 AppEventListenerJWTCreatedListener:
 tags:
 - {
 name: kernel.event_listener, 
 event: lexik_jwt_authentication.on_jwt_created,
 method: onJWTCreated
 } 
 # src/EventListener/JWTCreatedListener.php
 public function onJWTCreated(JWTCreatedEvent $event)
 {
 $data = $event->getData();
 $user = $event->getUser();
 $data['organization'] = $user->getOrganization()->getId();
 $event->setData($data);
 }
  • 55. JWT Events (success) # config/services.yaml
 AppEventListenerAuthenticationSuccessListener:
 tags:
 - {
 name: kernel.event_listener, 
 event: lexik_jwt_authentication.on_authentication_success,
 method: onAuthenticationSuccessResponse
 }
 # src/EventListener/AuthenticationSuccessListener.php
 public function onAuthenticationSuccessResponse(AuthenticationSuccessEvent $event) 
 {
 $data = $event->getData();
 $user = $event->getUser();
 $data[‘roles'] = $user->getOrganization()->getRoles();
 $event->setData($data);
 }
  • 57. dvajs/dva - React and redux based framework.  https://github.com/dvajs/dva
  • 58. React / Redux / Saga / AntDesign
  • 59. > Use webpack instead of roadhog. > Use apollo-fetch for GraphQL calls. > Use jwt-decode to interact with JWT. > Use LocalStorage for simple key/values storage. > Use IndexedDB for encrypted and/or more complex data structures. > Use Socket-IO + Redis to sync & communicate between API & ReactJS. Tips
  • 61. Symfony API + Gatsby ● API / GraphQL
  • 62. Blazing fast site generator for React
  • 64. ● Build● API / GraphQL
  • 65. Must have plugins • gatsby-source-graphql • gatsby-transformer-remark • gatsby-remark-images • gatsby-remark-external-links • gatsby-plugin-sharp • gatsby-transformer-sharp • gatsby-plugin-react-helmet
  • 66. Choose the right tool for the job
  • 67. Thank you … Questions? Feel free to ping me during the event, at the parties, after-parties, and twitter @jmolivas