This is a demo project using API Platform, Vulcain and Varnish all together! It adds Vulcain support to the API that I created during SymfonyCon 2018.
To start the API, Varnish and Vulcain, download this project and run:
$ docker-compose -f docker-compose.prod.yml up
The API is now available on https://localhost:8443
.
To execute the JavaScript benchmarks, go to:
* https://localhost:8443/test-min-waterfall.html (maximum waterfall effect)
* https://localhost:8443/test-max-waterfall.html (as fast as possible)
Results will appear in the console! These files are stored in the api/public/
directory.
A benchmark using Symfony HTTP Client is also available, but you need to edit a line in the vendor
directory (to fix a bug)
to make it working, see the comment at the top of test-http-client.php
!
$ php test-http-client.php
To reproduce this project in a raw API Platform project, follow this guide!
$ curl -L https://github.com/api-platform/api-platform/archive/master.tar.gz -o api-platform-master.tar.gz
$ tar xzvf api-platform-master.tar.gz
$ cd api-platform-master
# Master version has optimizations for Vulcain
$ docker-compose exec php composer req api-platform/core:dev-master
# api/config/packages/api_platform.yaml
api_platform:
defaults:
normalization_context:
iri_only: true
# ...
name
(string
, not nullable)
docker-compose exec php bin/console make:entity --api-resource Conference
New property name (press
name
[select the default answer for all other questions]
conference
(to-one relation with Conference
, not nullable)author
(text
, not nullable)title
(string
, not nullable)summary
(text
)
docker-compose exec php bin/console make:entity Session --api-resource
New property name (press
title
Add another property? Enter the property name (or press
summary
Field type (enter ? to see all types) [string]:
text
Can this field be null in the database (nullable) (yes/no) [no]:
yes
Add another property? Enter the property name (or press
author
Add another property? Enter the property name (or press
conference
Field type (enter ? to see all types) [string]:
ManyToOne
What class should this entity be related to?:
Conference
Is the Session.conference property allowed to be null (nullable)? (yes/no) [yes]:
no
A new property will also be added to the Conference class so that you can access the related Session objects from it.
New field name inside Conference [sessions]:
sessions
session
(to-one relation with Session
, not nullable)comment
(text
, not nullable)rating
(smallint
, not nullable)
docker-compose exec php bin/console make:entity Feedback --api-resource
New property name (press
comment
Field type (enter ? to see all types) [string]:
text
Add another property? Enter the property name (or press
rating
Field type (enter ? to see all types) [string]:
smallint
Add another property? Enter the property name (or press
session
Field type (enter ? to see all types) [string]:
ManyToOne
What class should this entity be related to?:
Session
Is the Feedback.session property allowed to be null (nullable)? (yes/no) [yes]:
no
docker-compose exec php bin/console doctrine:schema:update --force
docker-compose exec php composer req --dev alice
# api/fixtures/data.yaml
App\Entity\Conference:
conference_{1..10}:
name: '<catchPhrase()>'
App\Entity\Session:
session_{1..100}:
conference: '@conference_*'
title: '<catchPhrase()>'
summary: '<sentences(3, true)>'
author: '<name()>'
App\Entity\Feedback:
feedback_{1..100}:
session: '@session_*'
comment: '<sentences(3, true)>'
rating: '<numberBetween(0, 5)>'
docker-compose exec php bin/console hautelook:fixtures:load
See api/public/test-max-waterfall.html
and api/public/test-min-waterfall.html
.
See docker-compose.prod.yml
.
Created by Kévin Dunglas.